Dab tsi yog kev teeb tsa mock?
Dab tsi yog kev teeb tsa mock?

Video: Dab tsi yog kev teeb tsa mock?

Video: Dab tsi yog kev teeb tsa mock?
Video: Yog Rov Tig Tau Qub Kev By Nkauj noog Hawj 2024, Kaum ib hlis
Anonim

Teeb tsa txoj kev yog siv los teeb tsa kev cia siab rau ntawm thuam object Piv txwv li: Ntawm no koj tab tom teeb tsa txoj kev DoSomething rau thuam khoom. Koj hais tias, thaum lub parameter yog "ping", txoj kev rov qab muaj tseeb. Tam sim no cov khoom no tuaj yeem ua ntxiv ua ib qho thuam los yog ib tug stub nyob ntawm seb koj siv.

Ntawm no, kuv yuav siv cov ntawv pov thawj zoo li cas?

Mockito xyuas () txoj kev tuaj yeem siv los ntsuas tus lej ntawm cov lus thov ib yam nkaus. Peb tuaj yeem kuaj cov sijhawm pes tsawg, tsawg kawg ib zaug, tsawg kawg, feem ntau ntawm cov sijhawm thov rau a thuam txoj kev. Peb ua tau siv verifyNoMoreInteractions() tom qab tag nrho cov txheeb xyuas () txoj kev hu kom paub tseeb tias txhua yam raug txheeb xyuas.

Ib sab saum toj no, koj puas tuaj yeem thuam cov chav kawm ua vaj tse? 4 Teb. Nyob rau hauv txoj kev xav yeej tsis muaj teeb meem thuam a chav ua vaj tse ; peb tab tom sim tawm tsam ib qho kev sib txuas lus (tsis yog lo lus tseem ceeb interface), thiab nws ua tsis muaj teeb meem seb qhov kev sib txuas lus yog muab los ntawm a chav kawm los yog interface.

Ntawm no, mock repository yog dab tsi?

Lwm qhov kev xaiv yog los tsim ib qho mock repository . Los ntawm kev siv a mock repository , peb tuaj yeem txheeb xyuas tag nrho cov kev thuam peb tsim nyob rau hauv ib qho chaw, tsim kom muaj kev pov thawj zoo ib yam tsis muaj cov lej rov qab rau txhua qhov kev xeem. Txhawm rau ua qhov no, peb tuaj yeem sau cov chav sim yooj yim hauv chav kawm uas muaj cov MockRepository piv txwv.

Dab tsi yog mock hauv chav kuaj?

thuam yog ib txoj kev / khoom uas simulates tus cwj pwm ntawm ib txoj kev / khoom tiag tiag hauv txoj kev tswj. thuam cov khoom siv hauv chav kuaj . Feem ntau ib txoj hauv qab a xeem hu rau lwm cov kev pabcuam sab nraud lossis txoj hauv kev hauv nws. Cov no yog hu ua dependencies. Ib zaug thuam, cov kev vam khom coj tus yam ntxwv peb txhais lawv.

Pom zoo: