Cov txheej txheem:

Dab tsi yog assert tsis null?
Dab tsi yog assert tsis null?

Video: Dab tsi yog assert tsis null?

Video: Dab tsi yog assert tsis null?
Video: Saum neej tsis yeej hauv dab tsis tseg.9/10/2018 2024, Kaum ib hlis
Anonim

Cov assertNotNull () txoj kev txhais tau hais tias "ib qho kev hla dhau yuav tsum tsis yog ua null ": yog null ces qhov kev xeem tsis. Txoj kev assertNull() txhais tau tias "ib qho kev hla dhau yuav tsum yog null ": yog tsis null ces qhov kev xeem tsis.

Yog li ntawd, yuav ua li cas koj lees tias Equals?

Qhia . assertEquals () txoj kev kuaj xyuas tias ob yam khoom sib npaug lossis tsis. Yog tias lawv tsis yog, qhov AssertionError tsis muaj lus raug pov tseg. Incase yog tias ob qho tib si xav tau thiab qhov tseeb qhov tseem ceeb yog null, ces txoj kev no rov qab sib npaug.

Tom qab ntawd, lo lus nug yog, yuav ua li cas tshwm sim thaum lees paub tsis ua tiav hauv Java? Yog tias kev lees paub tau qhib rau hauv JVM (ntawm tus chij -ea), AssertionError yuav raug pov tseg thaum kev lees paub ua tsis tiav . Qhov no yuav tsum tsis txhob raug ntes, vim hais tias yog ib qho kev lees paub ua tsis tiav , nws yeej txhais tau tias ib qho ntawm koj qhov kev xav txog yuav ua li cas qhov kev zov me nyuam ua haujlwm tsis raug. Kev lees paub yuav tsum tau siv los txheeb xyuas cov programming yuam kev nkaus xwb.

Tsis tas li ntawd, koj yuav siv cov lus cuav li cas?

Hauv assertFalse ,koj yog kev lees paub uas ib qho kev qhia ntsuas rau cuav . Yog hais tias nws tsis yog, ces cov lus yog tso tawm kom pom thiab cov kev lees paub ua tsis tiav. assertTrue (lus, nqi == cuav ) == assertFalse (lus, nqi); Cov no yog qhov ua haujlwm zoo ib yam, tab sis yog tias koj xav tias yuav muaj txiaj ntsig cuav ces siv assertFalse.

Dab tsi yog txoj kev sib txawv ntawm kev lees paub?

Ntawm no yog ib daim ntawv teev cov txheej txheem assert:

  • assertArrayEquals()
  • hais tiasEquals()
  • assertTrue() + assertFalse()
  • assertNull() + assertNotNull()
  • assertSame() + assertNotSame()
  • hais tias()

Pom zoo: