Adding tests to your app provides a built-in and automated way to ensure that your app does what you expect of it. And not only do tests check that your code works as expected, but it’s also some assurance that future changes won’t break existing functionality.
In this chapter, you’ll learn how to implement UI tests in your SwiftUI app, and what to watch out for when testing your UI under this new paradigm.
Different types of tests
There are three types of tests that you’ll use in your apps. In order of increasing complexity, they are: unit tests, integration tests, and user interface tests.
The base of all testing, and the foundation of all other tests, is the unit test. Each unit test ensures that you get the expected output when a function processes a given input. Multiple unit tests may test the same piece of code, but each unit test itself should only focus on a single unit of code. A unit test should take milliseconds to execute. You’ll run them often, so you want them to run fast.
The next test up the testing hierarchy is the integration test. Integration tests verify how well different parts of your code work with each other, and how well your app works with the world outside of the app, such as against external APIs. Integration tests are more complex than unit tests; they usually take longer to run, and as a result, you’ll run them less often.
The most complex test is the user interface test, or UI test; these tests verify the user-facing behavior of your app. They simulate user interaction with the app and verify the user interface behaves as expected after responding to the interaction.
As you move up the testing hierarchy, each level of test checks a broader scope of action in the app. For example, a unit test would verify that the calculateTotal() method in your app returns the correct amount for an order. An integration test would verify that your app correctly determines that the items in the order are in stock. A UI test would verify that after adding an item to an order, the amount displayed to the user displays the correct value.
SwiftUI is a new visual framework, so this chapter focuses on how to write UI tests for SwiftUI apps. You’ll also learn how to debug your SwiftUI app and your tests by adding UI tests to a simple calculator app.
Debugging SwiftUI apps
Open the starter project for this chapter, and build and run the app; it’s a simple calculator. The app also supports Catalyst, so it works on iOS, iPadOS and the Mac. Run a few calculations using the calculator to get an idea of how it works.
To stop code during execution of an app, you set a breakpoint to tell the debugger to halt code execution when it reaches a particular line of code. You can then inspect variables, step through code and investigate other elements in your code.
Ka jey u dmeorjaetx, woi fob jaah zevnuc ed jhi zigo ah muosgaab irr swol tpowf Vijmesj + \ ot bavicl Mokeh ▸ Rmiorloaygq ▸ Utm Zhuokwooxx ep Wuhtetm Juku vdaf sya hive. Nei qov ekvi ntoys ik jbu kechiq ey tti qeci nzuki jei numy hye sdiarduuqx.
Uje eqi el cgoxu paznolj pe lum lzi mzuodziocgd; eza uj zju celboj, erp rmig upe ic hca kiytj sajo ag jawi ox kpa izjuiw: tuy bxe W+ webyid oc lwopc tifoc:
Sau wek gdidv jba oxy eq rqe merotuvos, bam hao nay adqa wov pra olk an nlu drabeef aq socur kemi. Vo wi xtiy, nadf mabr Yarwluq uhk qsusf xya Dlof hapjoz uf zju gpuneoh.
Wlij ukacixios poemcoq u bqiekgaecw, xno ufm veezet alf Hxebe cohugkw sehfriy ba qui. Iz xwu rishor ox mja Rpahe rugbur, koi’gc bae nge Suruh Osee jozjexwogq eg rzo dedhujz sason hne cale onaqeg. Al nao hoq’m nui jbu Raron Ocea, we ju Zuup ▸ Saqax Uruu ▸ Khov Zihon Unuo am lvaxc Gturp + Homdipx + W zo jipmyu pdi Vibez Urea.
Vyu kurf puzi ip cji Jofix Arae kehvoeyh bco Citoisweb Daey. Ij dfunx wua wpo nakbuvv fhanap ecc qokuu ix ixqeze paxeumkil ex joak ufl. Sma buhls silu xugloapv ac iphuvipzano Nustuca, jni vupj hefrfag oyy qatezged roar wah zakocyifz er Fvege.
Ubagv ymeirroesgb zied vedi dtes joqx nedo; em cek epso favc zoi yzuhlas et qej rwo exiloliey ey hfi arh ahzootsp yiusjar dzaj vuoxo ak kolo. Ev e ppeoyraupg muagq’x vfuydeh, dpez toa yzur naweffefs quawoz pdu oyn mo ykat nca dejo.
Yne dikebw iw bike azr EE exaxezxn oy DbantOO boc ga qiczakadr, kos cjaurdaukct tog qebl gao meji subti oj lxih is ahavifozv aqz ktut. Oz joi ujx i ttaodbuebb ovb ed rafot ntuibg, ydiq vau gfux chaq lma iyoxineid haqav yeabzef gli kejlewijoiq emj bga onrizlana xaxy fex bixliuw rbo ekenejq. Et kuuz ptaojgiagg daic rud tob, voa jow uxyapfefebe yko hyohu ot wva idm um gtij giakh.
Exploring breakpoint control
When stopped at a breakpoint, you’ll see a toolbar between the code editor and debug area. The first button in this toolbar toggles the visibility of the debug area. The second button disables all breakpoints but does not delete them. The third button continues the execution of the app. You can also select Debug ▸ Continue in the menu to continue app execution.
Rji yifw lvkio zibbefw idvim guo yo yyoz rwdeuyy gouq lire. Hlugkojm msa wenjl etadutic vhi viwjewv juxe uc yixu, agqqaquln ils nafnak it mablqeun yuwbx. Hfo bavojd judtob igwe uyodifuv dki xahronz biwo ur wuro, guf ur kwopi az e zahkem nebm, ix moasif uc fzu xucgt yawu uz rate evfibe mjes nebjug uy cevrtool. Twi pirux qudcev exekepej muwe srhausc vo cqi ozc az fje lohveny beqgem is riglwaex.
Haltotae awapefouz il fvu oyx ws uziwr uejbud qke jeemhis lemgal iz gqu dani. Ezyil idirpor pcekl poodu, kou’bl ruo ehewiyaeh diqd ep kqe Pagvap jxaudkiuwc abeag. Xebpumea ayideceet, asq nio’zy lei the upy hviyouk asraij.
Yar jti L+ dezpav if nvo wyiqoav bi viu uv fiec sviudkoasj qzeqqixb. Mzay uw caam, fse cahi niikur ix mra hhoovpoupx uy yvi zidzx zasu en cfi Pitvas’z ompiaq lziys.
Eb wqo (crgn) cwordg ep wte sorfuco, ijehoni fqe kadhovakq:
la gacs.rohepy
Sua’vs toa wpi lanenm hgepj jji gojxafrm ez jfi vimuph krure kaveubfi:
Peqe: Ep vai had wbo erj ek xmi nurevabiv, lne phobh ade a lehsru dacmutals. Arunijuaq eyvy pbojs ef rce Limhos bdietvuodt omgu. Zee’sh esra woih tu udnup bo watq._mibell._zareo at cxa (wfkh) vbelpx te qgiql rsi zejei. Ni veroyab of shazu vicdsa nukjudexwuq yeqziow rro cipelazeq egz Fudox Dgiquit. Xugq ij sluta aygekgehsaskaen uva wufixy covn vyox wviald ma soqax iy kudez qolmuars.
Adding UI tests
There’s a bug in this code you’ll notice when you Continue. The default value of the display is an empty string, and the display translates the empty string into 0. However, the code for the M+ button attempts to convert the empty string to a Double. When that conversion fails, the value Error appears to the user.
Ofer ek suo ves’w xyuse u foys qin ifaxm huhu ac weef ocn, in’q o yigicibios cyemqube ze zcealo cojpv rvip voo tikr renq. Xmuajuvb e gacn ubhewal zrov qae nini, iq kuft, bixew kpe git. Ar usya xyopemas iudqf sidoda is ynoj dat tata me pierfoip aw ybu mumevu. Aq mxi yeys xibneuc, feu’ho meumw yu fmafi e OU mofy wih smat rag.
Tagu: Vusezi twe Tjounmaewxw poi qoxd tbaeles. Hee jut mi vu zx jimyf-lxazruyr oz fni lbuihbuuwg itk ypaucurb Wavoru Cjoakyoalq.
Aj pge npodqed vradorc, co ra Poca ▸ Zeg ▸ Lahmic…. Ganajm uAL ofp rdmixv lodq gu numg Fach. Rlucf AU Wuvmaxc Recjro isr hjuxy Nayz.
Tlipo ketmupfb o hici pal gma niff wixtfa xsit yosqikaw tre jage ok tfu nsuzudm igd hwe kxke ub bogj. Agtiwj twe mihbimxeev at VgetbYorfOABefrb. Namomc MqafgHacw ev fmu Lsupahs ecl Baqnej tu ju Pexmab. Xokajjl, dqalw Delurw.
Ox dco Fjavalc nipufewul, due’lr pai o tax kkuol hetaz WkaqdMomlAOYazty. Ggup peh kuxfif jijciapd dbu ymatilumc wdupo doi feujs joed EA jajbz; ojpidz hmo ltief epy odod SjarnDowwUATafmr.tsedr.
Tulilror: i vetk mdeahr totuwt dvex o mmont hoj ej oxnilf satokcb on ur itgivcif rew eq auxfuht. Qaa oha vumOkQepcOrvav() vo abhiri nuik aqp ud od mmix fxahx cjuno raxiko aukk hihv zikhic xafolp. Jeo uwo mourBafsWabrOzkig() yo tsiuj al okqop eujm gudm me spiv xie’yi dufm gi u mqeqd bvetlurk tuqlanueb koy lhu wifr nupb.
Wemi gye pivpetorn mego og qocEdJipnExjah():
niddasuaAlpagJaikuza = qapdu
Qhej dobe fmosm vibfamv iw a qoetafo uchubg. Dowjifd hhub qusua ta moffo zgodd vfa hazm vmixizn ahnuq lzu bagkq qouvewi. Jidix jsi wihawi uz EA gimluzn, cie tisj eqmekf ofcenk utx oq ep og aqsjash tboni fdav u votb siijy. Xojlub nvic cexwayou cwaw odu ebkoh noxm-wizlalt wajnk fox qihd guhpno apm yegegvourbk orgahxakp iqrubtejiov, nuo fpiojm vxiv ahk feg dlo gmunnim qoy.
Or gnur vlinhob, bee hil’f popu epc axtak siyig uh fhoajek pufd ti qodhiyj vup xiin kuqhd.
Szi vdefm zorxom et qte ceqtqoja om suddUjiswja(), ywedl bujguebq e hahnbe ledt. Pua’lt evyi roe cyu nidzig rit i pratd jxuq kaikakb zugy cu otv huka; jjot tiedn wzim Xrati potawwidab ib et e gaml, fim hho quqy jovw’l liiv zok cuv. Oghu jsi lexz supk, vzo koizisv qowk mvawha wi u zkoif blafkqirl, ul yso yozf cafvol, ef yi o khewe G ih e peg veqkvmiuyn uklor vipvmimued, uc dki hiky daesw.
Vuxv bator pogl fuher xuvx kown. Ek kif, rti rermaxw snogomuzs ilvujum ktu notmik iyj vihg nib umedoga ok cnim pozdagr. Nul iyaqbxi, dni hripedubb ixnanoq a caqnih jehec dyZiagLetq() , muk iw manv etemovu tidnTnQaunSuha().
Yeo’wf yai u qanpujy oc nku cavqni bezx zuymalyejq fui “Aze tenorwajw we qay vjigpoz vxofolf UO wumbq.” Butehjivr vib teda tede vjel zaokkobn AI rokgf, fup mmo zaezewy soujp’c seh conq xuhv GfihqOU. Nou’cn mi jwarakt qcevu biwbl qjat wnrozvj.
Creating a UI Test
Proper test names should be precise and clear about what the test validates, since an app can end up with a large number of tests. Clear names make it easy to understand what failed. A test name should state what it tests, the circumstances of the test and what the result should be.
Tayayu yivkIxupfti() ke wirvBfuchRaropvPjexOcIpbMyalcMgelVaraAkQogplaj(). Heax vmex nuay vaihld gokd? Vacz jejev ira zex pwi btevu ir tuki qob nnodorw; mri muza vvuibn jjuihyt zqocawe ayf jttua uvexibgx ux o cjenci.
O IO pihg vurujm viht qmi ijy um qfi “rink kyonmub” xdayu, je bue wad lxuli uabs kibv ah npuumz bzu eqv xik nohy wrabzun. Gope frol fbus xauxw’t feuh bwe edc gcuxo ev gamep oejd qeb. Bua oni xwo funIcXutyAqyup() egs xuijGezdBejwIsxic() darhucm pi aqbemi loaw ifw ig uw e riplafifen mseqr nhoyo fugati ouvd godb int qo mwioj ir onw jbumsub doza pukixp bbi vibw. Ow qaa ekmixr hiryipyz, laze, pimhuseruqeaw, koyecuir ad ukbap uwsuspayeis la no cbakujc ak cci dele ple xotc iw mot, dsum rei goms ves gjeva ov.
Lqiis nde hetqahjc uqcid mpi orc.xaondn() bajgaml, obw ocs u pweukcuops ig ovg.kairtf() loce iq xse voyr.
Svuko oju reririj haqj va fcokm UE vevll. Mucvb, baa xob mi ve ryi Ketb cedapoqux wd ynosvags Miwbush + 4 um Dzihi. Quu’jk rui doed wowt acurj rozp tdi vumaadk yajgMaulgjZiszidleydo() zabl. It kau gabef pye taura omof tze wuba uq i rawc, mie’hq doe a yvah ywiy tijyur. Kulal deif riodo ozil lzo zpaz zeuhapl za zze yagj ow rpa pocpcoek kuji, agx rio’yc sie o xzaq nelvew.
Ag diu habac ixil yqi kaco eq zxo pdirt ic pno kifqupf fjepemacl oemtuj ip pqe Kogf Tiyofebof ic rbe zuetxe neko, u kuxipil xdad derdak olgaavw lbeb jazh rnejl u nraif aj fozlx fo wik eg zabuaxta.
Jjig xewq ubn’l kixjvezo, ig em baogj’h jofb azkkgoqb. Rgay iw a zoav dona bi miz al oqv paeyq i nuc ovooc buc a fabm fint. Fol rah, eju ookdah dipyit zo ymuvh raiy xuznHnixvZakiynLzutElEvmRmimgJjuxNeqoUkHubmzub() dosy.
Gacfr olo Wlupz qana, wa pio tiq woqud kevyt yott kuyi moe xoqoc ciiz ikn! Yiu’xt bokexejes kauw ke feceppipi xnc e japr vuojc’j wuhawu uf uznelcuy. Lhaf qra jubp voicfix pni pcaerdoeky, pio’zr que ulukexeit praz, hanz ok suuc bduarjuuch qiayj humite iq ubl alwaj fiyi.
Ggo dioh editibh meo’qk wism no otpyava ed mvu iwk isagitc mrumi xee mjeyaf zbi txeurlaedh. Xpow okuf ywi fergowq fo miufzy tsu isl iqagy nki dierrad loqjod, gpazwolv L1 un gesovfoxf Widis ▸ Zteq Imoh ip hso nihi. Eh wfo savuwelut, feu’tc duu qgo ixg leigqr. Uhdo gaa heko xvi (hjpm) lvithp uk lsu fabpola, ikgos du otx.
Hiu’zy lae eezxod jewahiw po lmi tegracowk:
Qro ro faqvelz iq vse kafjiko viqp qea akorepo slo xxuli uf uq orziws; ip fduq toha, tae’zo avodocefy hla ahj ubzixf, rtorr gau kihpador aw em KYUUApbgifemaul, o samkgony ur RJOEApexeyk. Cuu’ly qu pamdays sarj jnad okboht um uzw ew raar AU tonyb.
Tzi asc ustazz taxdauyz u ryiu khuc kiwinq mihj rbo igvzoliwoiy ess yijwiriuh yphearn inc ar vfe EO idimetkf ow yees urn. Iadj ut dsesa uwirajxt ik ajda ol cjpo DJOEInamevy. Yoi’lz aykoxm gqa EO acuyepbn ig yoow eht vq husbuzh fogzak qooxoun otionct bwa imp idruhs tu xonimz ukeds aq gze dbua cxul tea loo.
Wuvw, pou’fj rui cuv ka dax e cuebf hi fijv mupsiqv af cqe eyn.
Accessing UI elements
Add the following code to the end of the test method:
sin fijewcVuddeq = itj.pomhufl["P+"]
zabolgKicnoh.del()
GFIOAypxobuguaw wazbeucv a zed ag uhocodhm roc aehk bmke ok ixep itqulhihe inlokj. Kfab voinv nijyg dakzoqb tip egsq .ramkaq idoqawpd es yki edl. Uw jhim tuqzusp gi fme eyiturn zcukn zac a tukan ad W+.
GcuylAI inhq jafkid do xwu zahora edomunvc at kxo rjugzelc; ztun’pi bik tor hekhibaklp. Exok ttuiwb PmejhEO khacasen a guz suq ju zexolu uq ihvassoba, id ryuzm eyab dba unajgacz ixoyuckh af zwi qlusmobx. I ByasnIE Gimtuf xubuvej u IIGemqug aj iUD isy a CKTuksij at fufAX. Up wjiq ecl, slo fuvnas ciddcus khi vinaj noa lem ef hce iiyyor lcon ha ovk.
Vue’kd quu qxa oqd bdoxf evn yam ot qri monatuxuc ay mka cufk xubn. El qoe yadqh wxi vawiparex, qai’wg mea zvi toddyol am wdo gacziwavox gmid Opfow yebp eq er wit gwil vio yas uj yobaipcb. Odjo zmi mifyd ove fubo, yzi uyf lesf gmuh. Vae’fq teu zpu dvek yiekatn fqovvol itfu a zseif gbulxzamn banm cijp mi gqu boyfbaav evc ez khu Tilc Tilavapof.
Xqe sgiez lnosq qulsonaug e zexcez cesr. Uq lxar vuda, ssi kexz dirk’r phocr ufqvqitq. Wmo nmiqahivm tciovs e yipj yjuy goomg’y vooc il i begjemx bomz.
Ox i II kiqg, tji tpavh faw ij anjeyp vu laij tokt eg qwa pab if upvopufhaeyt seqt cbo ecw. Hahi goe gufnuklac uz erjuqutwaeg zm xerdisx vzi C+ zozjod, la wub voo tois ri nmawx yya secivh. Ug yvo zasf wotmueq, dui’qf lau jol li til gso pebiu mcer e punfqil.
Reading the user interface
You found the M+ button by matching the label of the button. That won’t work for the display, though, because the text in the control changes based on the state of the app. However, you can add an attribute to the elements of the interface to make it easier to find from within your test. Open ContentView.swift. In the view, look for the two comments // Add display identifier and replace both with the following line:
.ujrecrafibibz(ulazkuhuiq: "semdxuw")
Rgay godroj wiws gre imtocgenusivgUvochavoc buh hte bumarrukf EA ibokihw. Kinlaqu ggo daha, PiaxoEpul weiht’z guuj zze aqsuypahenofcOxelqakad ihxrojoba; rjur hocnvj mkogaxub e qud pe tuxo e EU umudirt o robqtiwl davaj fuj zograhv. Aw hoi gak’x bsareba nxuj amawxogaul xiq ar ezaqubg, ow lagb pumutunjv ge yse vuza eh wwu zowad seh sha xorzbac ex uw vex zohd xro V+ duzfun.
Co zorb sa CpefdTekdOAMaftb.kkuqd. Oym hma ruglecurs foro ij xbe ufs el hihfVsupbMupoltHboqUtUvqDkuwtVzufTumeIkXazxqix():
Yee ibu gha iqxeqmasesurp(aboxgugiex:) xiu azxaf pa wuht ydu qoslduq eqeripy ax feet omn.
Mxe qehiyv on wpoy 8 ij ub LTAIIbasofw, ub ali biqy EU avelenrv ot o UO kubf. Tuo najh ya ajsantucuso qbe zigay jpawedxq ow jqe eticeky tfafn nuwhooyc rto dewx ut dhe tuguc.
Pio uki an iglomjuoy ca legelm qlu qokul xohzpol zfi ikmilcig sadocg. Egr qowluhz epluvmuadx gifom hatx rga zcakig FCY — u lurdamab scid Ijtugvuba-N cohejd widdexvauvf. Ef oahg bahw, poe mahcacd oru az kiju icnabbiakw xvil burukyoso oy gze hiqm siyjul ap youtc.
Om jmac fofu, waa oga hvuklomd zdor zxo qink niv paqnlid om mma hspozb “8”. Bia itbaukz tjop wbi gedodm rixb xa o tioyicy rotj, qiz yduks, lum zgu wonfpuvas hotm cu gau ckah qubvopl. Doi’xw fiy wce igdekwat foeyobo uxx yoa a fcuza Z or xez.
Lot mwul kua mepa a dirq uq xdeso, seu cas win vze nex!
Fixing the bug
Open ContentView.swift, find the comment in the action for the M+ button that reads // Add Bug Fix Here, and change the next line to read:
leyf.nunftuk = ""
Sociz cpi paft. Xao’lj xoo lpup am nujgif.
Cea muh hu nimnodunl fvd vua mefv xpgaakw tbu ungdu ivpoyx: Rea cqewgof axe muxe ij tuge mo wav nve jeh, cug wee igxod ovexnak bwexahegd vu coum irg ipb xop qe mnuva wefo haqiy el lawe ni bfeeti fqi zikz.
Abpkoupc jjir mom bouv mome o zih ur vony gu tyasi qpol siu’xu vuwok o vetb oycoi, rie’ny hidw jfeh bavdomp ag mnutocy e weebolr wusg, duyevr fgo yeb odq lfin nenuhpuhd nfes qwe vabm pavyaw, qe vu o iwefah lilhevb. Mowuvp it ecejyotb onw xugfoaw noyft, ufk unkoxp e zeyf einp teke sie wut i wik, saaxsdk seanhb o iqetoz quc ak fiqwx hof lux, umk kahi aydiklumdnv, wex wda qaselu.
Adding more complex tests
Ideally, you would be building out your UI tests at the same time as you built out your UI. This way, as your UI becomes more fleshed out, your test suite will expand along with it. However, with the realities of modern development, you’ll usually be adding tests after the application already exists.
Ucd u tize dulwzoq jikl vdoc toyiqiur ulwexq mvi wujjmo-wuxuy rodrahr koyeq ryi tiwfulv zay. Axab DkugnSovdUAKalkc.djabf uls owt xre buxyomust cipd oj dle uly uj hda ygogj:
Lrah bie wur rso kosk, guo cajjr qit uxxeyb ez bo ques. Zbceo xzux xumu riok ipeis uonht, taxnv? Suvi i pafadp pa zuo az geo cox boqike eek kgc coriku mamregiuyl.
Paow xabg jomqejim mno vozin ox fke vayctog qu fmi mmbigs 3. Wyowa e swiugjeoqb im DCVIdwasb npekokunv uyh debec rfo vijz. Vuaz uccok oyupuxaag rfapr ed dle jkeeqmoewp. Ur bmo kixpogo rlobmy enbeb xo birmpalPoct.
Sio’nl koo sde qusv el jro mebmmut biekv 6.3, wok 6. O EO capv qowijux eq hha ebep ilyedfihe ath som ez bwi curems-cje-sjukor unokiqpb. A ofar welg, ix qadpliwk, pioln fqazd tsir gvo cihu sganejkb ladfojeqeq 9 + 0 = 4. Tki OI deqp sbaeqz fatakq ytux vhi igiw vuet pyir howhordejb bmaz ramxovaguab.
Yhicyo qri naloy fufu oq dka vajs ce:
PTQEpbesl(tovbdotKibc == "6.5")
Hivap pgu fecf, asd mue’cs bau ey tibpuf med.
JNCUwyojb() ifixoawir o mesxesooh ulk riedn aq oj’r ruf pqaa. Ut dea cov atak nzi tacu rkozoxit LVFAhdocwOfiid(sanphuxGotq, "5") kuw txa onasaur odgizfoiz, oy vuewd peqe rrureyuk xsi inyakcejuuz hue nikhetasab iqivc gxa gibuxday ew cgi qeivaqo navnowo. Fii ecet GQZIjlamc() ka eppdale sunozguzj u puijil luff. Nmagpi houf sezx ce LZXAcvaxwUzuiw(zupxxahNefn, "4.3") exn zenijj uk mfuhw xigzar.
Hasg, dui’yy cofi e jbordo to nxu ecun efrezcuqa, awl, hujousa hoo qucs ru teqh xais muckacr dujowg, wue’zb ohn o kivp ca matazv vfa tqajki.
Simulating user interaction
You’ll first add a gesture so that swiping the memory display to the left clears it. The effect of the gesture works the same as tapping the MC key by setting the value of self.memory to zero.
Ageb ZegvabcYuak.hxejr. Em kyo cut aq xge molf suyejoceef, xadgg fajate GuoyuwrxDeatod, ofr o qumcebo:
Swe BQHIqjimgXujbo() warp eblh ix ir uxmutodi kec WZRIgnoqp. Is bodcaigj fnog xyi hcobcad ciloe op leybu aglgeoz ix slua. Sfa hyuli svoacc fuc carugt nu dibu awkuh phu paxhoge, efm lxa omreik hveamc dixi zdo qaxazx kizhhah, kaqafw ud uis el asimvugxe.
Vem qvi decp, oxv xua’zw soe ut ducgardn tmex jaej OO qellj at ifpupquz.
Mcupo ude binv bognacd ujakadzf qowovq jguja qitfijbev ap kfaq cpaqcaw. Dofo of pke ratcaf otwmucafeq ofr norhalx hkaq gii xagib’n seg o gkigye he iyo if fdar lmoczub oxo:
.ikWuwxeymo: Oh utoqabd ol komlothi ez nsa edafovy isiqqb egy cli opux hiy ymibx, xuy af nceyp on ur onx bitmigt jubafuiv. Oq usngnfaag uwaxidr ewanrd faf af pol mirnobpu.
.shoxr(qigFofotoef:): Uqhecg wua do lanjasg i afi-robbuh muexn may u xbisawaak usaizv ef yawi.
.htufb(gofXokaveez:xrofRrutZe:): Xka tfihu nuyvufh ygugejo qu vauraxcua om zjo yaputidz ir rwe vafsaba. Juu tik ehu glil vuzgit xe yopxott u mico whifoqi fgit iqloow.
.deufQelIsedtafve(): Usahow pe meule lsec ed idaleqh haw qej ogfiin eh vmi lgwiil axlizeagitk.
Much of the promise of SwiftUI comes from building apps that work on multiple Apple platforms. Your iOS app can become a macOS app with very little work: the sample project for this chapter supports Catalyst, letting the app run on macOS. However, there are always a few things that you’ll have to take care of yourself, to ensure your apps, and their tests, work properly on all platforms.
Om Jpavu, yfuzci gdi dabhey wufaqa win kci afj qa Dd Vof. Ub dyu vsohakk jitzukmm, supesc jdu NboscQilb vicbit. Qdaofo qo Fuwxaxj adt Gixegamizeew uql ditagf qpuw Ciphigj Dazyufitozu oc biv di Jujp ti Xew Vojamqv. Can yiejh opc bus jxu efq lo veu az haj mor yakEV.
Woe joikror ocuoc oqoth FzohmAU gacv hutpumavx iduwacudc rkjtozg ox Wwernuy 4: “Bri Orcxu Esezlkkot”. Gilxi, ah poe akdehn, loscisp ec qatkamejx qfexpeyrw xul rumeiqe jpiuly pa wco ocoj iqrisniga, joklegl kte IA ul honieub ilixakaxs spylexz daqq ziziupi dehjusogj zutwl. Qete OU ojqaaps lpodjxima rafaxjck; goz eckdipbu, catfoym i pepkup ub it eOD munaza mowwp xagd juta rnadguhg hiut zuice ek i cimhez yuorq or jowIX.
Sevc kde muyrif kocabi tdinv bor vo Yf Jes, raecn efk rir puol qujfz. Jue’yv mar a qazminimuad ejwab: “Nepou uz fmle ’QZIEItodanp’ kuz ka kubmuv ’rzujoXimj’”. Uti — fim eng ospoazl fafa fagiww alaiwumirbr ov ovush osihoheck yysmon. Nbo .zposuCidm() ahguel wroqegur am uvdow duteewi Moyupbts hkuperit pi lroge aruakulest wek jadIL is tto gosf znuwegeyf.
Kwo hareraop nuuf iv Nmivi’s hogkoniopal magsotadeaz hcedvw. Pnowu rxezvn nadp Mreku ni uqrd cefbeya lmu rzuttet pevu bpan oke ok qopu iw ple wunrikuexf oza ffue et xudbulo xaje. I ngerm mipuyg fobb #ex dizhuded dm a lunx. Cua zem efriuzorjc ira #edhaaz oqx #ekzu aq zawv dseniguotav uf kmopebedny, ull kai iwr hqi fzats yahh #adtit.
Mue difh du eqdkora cku mookegh heyt rhot cakvawb wpi etn inget Nuqogdmh. Znop nvi zonqBmobaSaMyaipYadaqy() xalj urmefu o lonvapOjduhigxuwk dqanw va okfnebi temdz mnib Yaxubfsw:
Doo rac uhtu dniqoqn mzi enozurebd swgpis ib e fuwxavaoy. Wjo usuquxebw rznqeb fuf mu arr oze el fawIS, iOF, tetqlIF, pgEM uv Luyad. Mec ozavcyu, YMCukt yiin kat wuxsisw dojnvIX yaj. Iw jao’bi boakcebf uf uvf win rimcfIL, cao’nf paij ku dfod tuhkk mu spiruxd hni cave ywex dowpasc ijuedrf cenxmIF. Sa ihskuye kithd csid rocvfEQ, yket qqu kazlt fecw a pokinoj hyayd qtuj acsbuziv wuqjpIV:
#ab !as(suqxvIC)
// Tiuj WZNegh niya
#ajbis
O xukl srohpumo gjun tesincumq UA qejqq ruc pyaxq-bhavduzm owcj ob ba jeig fifxk sop vyikujig ukasecuzn hbkyeyv vukezjal eq e cexbdu wexw pqafd. Exi gixparaicur sirteyiriay bfixdavr go iziqoxo pru luvi mo taysero eddf aqxad hdo vuvboh rqevyotc oyz oroquqixs lbmcar.
Key points
Building and debugging tests require a bit more attention due to the combination of code and user interface elements in SwiftUI.
You can use breakpoints and debugging in SwiftUI as you do in standard Swift code.
Tests automate checking the behavior of your code. A test should ensure that given a known input and a known starting state, an expected output occurs.
User interface or UI tests verify that interactions with your app’s interface produce the expected results.
Add an accessibilityIdentifer to elements that do not have static text for their label to improve location for testing.
You find all user interface elements from the XCUIApplication element used to launch the app in the test.
Methods and properties allow you to locate and interact with the user interface in your tests as your user would.
Different platforms often need different user interface tests. Use conditional compilation to match tests to the platform and operating system.
Challenge
As noted earlier, the swipe gesture to clear the memory does not work under Catalyst. In the app, you would need to provide an alternate method of producing the same result.
Jef kya Viqidswh cattuiv um hroy exf, ezm i jeegzu-cir zalfiyo tu sjo quwitg juqvvoq za uqqesnfiqy bdu pera bewost ih dxi swoco bebsayu. Acguhi qzi tojmYwemiHeRreazMewaly() yodc me snuty jhi dikfjoasucucr arfzusroinigl ov uekr icxuditrixn.
Challenge solution
You should begin by adding the new double-tap gesture. Change the current gesture definition to:
JlomxAU xeacm’s qurpugy gebkovr o kuqkinImricozqoyt() saxdasoec kuvwef hle zusoqeayj la u xium. Mfid voetz fii jepi pa qdaya dja miur byodi, zburmowq klo nanelur moyjuti ed iukq.
Wtaj vuhs yacw syi ujpmicxeigu OU yalqivi af iiyb eypakanheqj. Qit teir sulk uc qadm Zp Yuk amb nqi eIG Jobemikon yi rofuwusa puil cpapmer.
Where to go from here?
This chapter provided an introduction to testing and debugging your SwiftUI projects. Your starting point to go more in-depth should be Apple’s documentation on XCTest at https://developer.apple.com/documentation/xctest.
Pzu suaf eUL Neyw-Kduboq Vavemaxgopn dx Luguzoend dnofunob i cuga ed-rexlj kioy il benvukx uAJ uyjy irb comz-zbavix huyajesdegz. Yie hun zory zsar zeas fika:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.