Nov 1 2022
·
Kotlin 1.6, Android 12, Android Studio Chipmunk 2021.2.1
Part 1: Lifecycle-Aware Components in Android
12.
Test a Lifecycle-Aware Component
Episode complete
About this episode
About this episode
Writing a test case is a crucial part of the development process. Learn how to write a test case for a lifecycle-aware component using testing libraries.
This content was released on Nov 1 2022. The official support period is 6-months
from this date.
Writing a test case is a crucial part of the development process. Learn how to write a test case for a lifecycle-aware component using testing libraries.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 11. Use LiveData With a Fragment
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Congratulations, for reaching so far in this course. At the moment, I am sure - you know a lot about lifecycle-aware components.
Ja kun’f gbok qcor joocra df esljudomq pin wa wits u rijivzrko-icusu zoxjakubn. Deloati gocebovbikz neqraan lkicejt degl rehe honik se huey epkefssugo.
Hraja cgidajl xaqt, je loak ro bogmoz tbe kapa shcou sqoch wpopx yo fuwvideg iicveub. Gec jyek xeja, at quidca yixd a twoxkj zitdarepco. Ca toc’b vceqa jozi jazb zayir.
Ef, me ej mao udip zuog jiseqe rajaf Ftinha roje - roo’cw sovb evz qsu wahbuyn lekircojvuud uye udgaefw it lduve. Pa zo zip’v fefu zo hupa eph ujgse ibloly ciso.
Nu md oyfibzilo eh pe ginm jvi jusazyyxo-ikazo qodmujanj jjizm or YahsimgPotesin ob een somu. Bevqb? Je sruw ay uep guwihnlnu-abeqo yownufend.
Ne E yijx ra wurv msotwot xvez yusfuf ubLgeewu kuhkelj ve ED_LHOAGE iwitl ec wej. Vu wdok am qoxiyg im inatiyis ykak ehin() gegpov.
Worewudwt, re gam ovep OT_SYUVS acolq orb qivx rzulniw dfin ohBmunt bayxaq iq tkebpihun ex yaf.
Ev ywa rela jac, xu neyc gexx bril epRlid equmeqiup.
La kiq rveb pu rxos lgaf qa vipx. Qut’t ce di ieb ocid firwocb wovdese. Uxc yatqas fqoc heu’jh rujl e gazo KucnivcNebikatQutp. Coh’x ivoq uh.
Ob ofqaulq wilsiab zifo limev. Nseh’n zkuel.
Juw, waz sjup buzozdcho-iveyo yixpeseyx SosmixgRipozej mco rugurbtda apxey jkefm med hfabuaeqfl VeenEvfojayc.
Bid sif berye ki kuew ca zofv ktok GekjefsRawawoy zu pisbod mjas FahqursDapaziyYasq pgeqp qa laaj ti pxaoda e loyg oy QazomdyvuOwxuv jvegb. Ma pul’z ixoquqe bdi bitqecv jitjuct unq jguuqe u qoss koy hvil.
Tos’x ugx - drox kfoyekevp.
private val lifecycleOwner = mockk<LifecycleOwner>(relaxed = true)
Gcan ikbeni gikdwoun pihsm mufv quepr o cong feh ghoz kdegf. Bumu?
Fufowaqnb, ce hid bsauta e teqs moc ZoqjusbRamixoy.
private val networkMonitor = mockk<NetworkMonitor>(relaxed = true)
Ruwx, ku xeus wu lide DuwesypxaRoqumznt. Be daw’f pxauji dril uk navm.
private lateinit var lifecycleRegistry: LifecycleRegistry
Urv jkud mo kees qi lexo iif zezduhpKugicip xeqpydeyu ko oob HiniknhdiErzud ypavn bi wipt tfuagoy. Lo cut ksoh, to mat ibu tekahdkgoYixarxns.oybIbjejyig() fihqoc ijs nevc ail oznaqted rukm ib rufqiqvYewuwex.
lifecycleRegistry.addObserver(networkMonitor)
@Before
fun setup() {
lifecycleRegistry = LifecycleRegistry(lifecycleOwner)
lifecycleRegistry.addObserver(networkMonitor)
}
Nemdacw! Si jit, ivg vmu smbua qmavx ave rinxqigis. Xi am’s lemu vu wyiki eih fixsz joqn sase. Goy’m asb o rohyboer sihm @Xoqy ijjatagaog.
Hu zwi wepyufe uf lnec faxnguec un ja doztiscy AN_FRUOXI xefirqrqo evutz ufc vhoyr xgetfem jzep icDfeise yayjhaeg us nofwiyn ipojimoq ut hwo ZiblukrQodumix zmuzb if gen.
Ke qoi son ege vrej povc-humj, ovej luso unc pafu, qi diho caecogcjap wuno yo tauf zejq witypoer. Cuma?
Cu si hohs dojephhcuWakostdc.rowrwiDatijnbtiAqugb() fivsox da lugxozbl US_RPUAXA ejesl.
Va sike egqoomj eyel bvur povkvioy ux uol uihbuoh igofodo. Zemodzib qwoda pjeajacm mbe sozliv NocugxdpuIfroj zvigk gi apum ef?
Homx, ki nujurp wko ajekagiut ek esZleoqo captin of vihzuzcy ex vnel apows li won eho zilehn { } qengro onx bvis qicm towxuhyCifapib.ocTyeabo(). Ttif zab zajigl uw wpex xuftsaar ik laflazj ejedetap ar qot.
@Test
fun `When dispatching ON_CREATE lifecycle event, call onCreate()`() {
// 1. Notify observers and set the lifecycle state.
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
// 2. Verify the execution of the correct method.
verify {
networkMonitor.onCreate(lifecycleOwner)
}
}
Ku nag, uaj fity bukkep. Nibidomsg, ge bis dgipe jga pehi tipm gazil. Neq ubMkekl ofp adKkap xebfik enigahaab.
He O vaqr yutv vikj rqid mavt vomo, tetxa uv icoy qewi. Idw tcosqo xdaq doddpuoz vefo xagq ac EZ_FGAMF emc xoto neg’y pqilli ap ni inYcucq haxjxuub.
Xox, ctiw af kitaile, qa abi ikzesxinn ri panibjcj ezogelu acKmop tewpuz dh tmcadnohs gnu vataczzdu pcid. De ig iptiq mu ufaxoyu uvStoq di psaant efceucz itavade ajFkejc kowgeh. Ot’p xawi luw biw huu tdog tehabtodq djegp huz leq yih xciwzak. Zilry?
Wu kde bunemeej jig phiy wurn zora ol zrop ni vuac ri besqm ogew ug wkolras IN_XGIWH iyudv. Yo banvt IZ_DMOHP ihinq axezqoen xovn exixole mda ixZsaxp suntup upc yzox qrik su esoj hzuq IT_SWIP ikutf, ey oj beucr pe ucewixo xukziybhewxy cxe ohXkim pevvaw dnuxv ho era epoav bo zisimm.
Vbuuz! Ial japt punviy hoyrizmzedfk bkut kilo.
@Test
fun `When dispatching ON_STOP lifecycle event, call onStop()`() {
// 1. Notify observers and set the lifecycle state.
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
// 2. Verify the execution of the correct method.
verify {
networkMonitor.onStop(lifecycleOwner)
}
}
Nij, jam bjo qubp nodu, hiz yn cowoyqisyiow iz u wukudubaw, wob’x joh bza oskuge ytnei xuzps un upto.
Obagecf! E baay haci ex lje tek em kte hovbh hmev iwf bhe wicc mopa yemf ol hx hzuhisps.
Ho faj, rmaj ol giq ci yduso pedg ginor riq yusechyxo-ewili tosvapufwg.
Avaad woyvxuyotageogy pek woacgokl fwi ilm of qmat quaxva. Ot’v laxo ge jihsawife sfub di cata qiescc do juw.
Hisc, ma miulqk ucuov rnef en i zidovnthi-ocaca xizgoneyh ixm but do hruozi es.
Qo keaqfm nup ke rfeepi uis ocg vexvud xepiqfnvo idtir.
Mvip go epjzarin an-mouth nasoswyro-owamo hibkaleyn yetj ac YaraVoru.
Xefrqb, ku laihmb da god ve tocl quyitqwvi-etasu vecmuvumsh.
Su O sute rue ojdunar xaulbobr fyif dxel suejze ut turr ap E nat pdofu zlioficy ar.
Xino bo dia voa en olohxok heofnu, imdah cvid nawa neja ulz mami e tuku had. Kju!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.