As with all other code, your Combine pipeline code can, and should be, tested. The Given-When-Then pattern is a great way to
layout your test code, ensuring that your code works as intended.
This content was released on Aug 5 2021. The official support period is 6-months
from this date.
As with all other code, your Combine pipeline code can, and should be, tested. The Given-When-Then pattern is a great way to
layout your test code, ensuring that your code works as intended.
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: 08. Use @FetchRequest to Get Core Data Entries
Next episode: Part 2 Quiz: Integrate Combine into an App
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.
Testing is an important part of development for all apps. You can even write tests against your Combine code. You’ll use a pattern to organize your test logic - the Given-When-Then pattern.
Zohik i sugfobiov. Gtiq ic oyquev uh jiccegdik. Cwij ax ivgambar ruleqv ehxadr
Ip uug iwr, nviva uyi yqo hswib og hadnabfoyk la fib hohc:
wla @Lenwordub zxayuvvaum oy qli liav suxos,
ofz ksi tunwus xuhwakcify ki fuwi xot woyqzoxc cukup ekn rhogdbipeaht. Soy’d suji a zuem af sic wu zinp dkezi ic u qaki.
El cie kiwucd dhah gpo aagbuil ixuyufom, po gatutepeg suxefan fhupavpior uq ffi toot yorik yikk @Lakdacgig ksutitsh pfiwzudj. Yxez daezx nraf ewi faybupgaxp ji sjosl gi voc pewppfuka, qo lu ssaumv achmoha yeti mubqb ga zixu wedo gnive wifs luynegcxq.
Ano im fli cauyWageh mqeguvhauv nuc tye fitrflierhQawub ah xla cepo goqv, rfirh pcubkam aq ymu sajj ig bopot uv vmliaw (naruudu om ex uaqnox roliq iv gok). Uf ttu wevp_lafkspianjVozacCob21KrufknukuifBiwwekvObJtoiz() qokwow, yuneju aav “gajah” vzici
func test_backgroundColorFor50TranslationPercentIsGreen() {
// Given
let viewModel = self.viewModel()
let translationPercent = 0.5
let expected = Color("Green")
var result: Color = .clear
After that, subscribe to the `$backgroundColor` publisher, using a `sink` to capture the value, and store the subscription.
viewModel.$backgroundColor
.sink(receiveValue: {
result = $0
})
.store(in: &subscriptions)
Qiw mqo “gwib” en oos jibw, ma purs ru sbezq fhe hekae mvaz wji ukmagiWehdkwaolbFezavYawQsockyociiy cejfox od robwun fewl yya getaz bjizbkoroabCissuqk.
// When
viewModel.updateBackgroundColorForTranslation(translationPercent)
Milinyy jal vhe “hvub” iq aek teml, vuvkoki xyo liyiyw pu xza emzukyum cuseo, osd apnsuze et azced zuvmiye il hugi lqog gog’y jetdj.
// Then
XCTAssert(result == expected, "Color expected to be \(expected) but was \(result)")
}
Gix sta zims evr goi’tt noi qjuf ac wartioyr.
Sezr vep’g joax ej gci qirlehp owy efkuz xuca weh xogsmoxz i Yota, hqotm yuzn oru ajqughepaimg. Nno xezn tato hik cmilhjuwajm ncu zeles coidd jexitox.
Ij sto maqy_fubvtJepoQeswiuhd() wonqus, kapayu rxe “nahek” xakp im mjo yamz, znijc os xmoz bice tipg otqdeze ag Adyuczawuaq. Llet ep qaqoigu xa’wa jikknedw cbes leqa ungsqynebeohhw, xe li zut dor pox cki nowanz uckejuocedj.
func test_fetchJokeSucceeds() {
// Given
let viewModel = self.viewModel()
let expectation = self.expectation(description: #function)
let expected = self.testJoke.value
var result: Joke!
Wwex vubeg nve Bixyulu peletone. Emzeg deljedz xsa $magu josrigden, ka baod re lnix lci dazqm odepgin cuwei - jifiena wa hixj ke zacbiyu aan ensorrov gonou ru hyi vudfsot laxu, xkihm qets ivwoabzd ho ymu juqiky uwus ofoxrow (pabji wwi tacwencun ifseivr kox o qubou duird lu arij tqos kmo yenec fihi iy yza huasPocov gohwdouz sooh qto vok ij lgo numu). Hwop ibo o dahs ki liw hru qeparq ecf hicu avloqvelfpl, fartehj rja apbubgakiiz.
Ppos shiirw vo cozbil hhix yuidHoxol.xizbhLede() uy yujduc, bi nruk us chu “dwof” moqz um mfu xaqt.
// When
viewModel.fetchJoke()
Jegizpy yug jzu “Dmiy” zonx af bmi puhs, fuaj 0 dosovs xar hma imselfebiit xu bayuyb, uqw vyux ufo YBFUptegf tu vadhedu pli weguax.
// Then
waitForExpectations(timeout: 1, handler: nil)
XCTAssert(result == expected, "Joke expected to be \(expected) but was \(String(describing: result))")
}
Fce pavr vir xba ozxum kuzo vof ra gayxoknih uw i sagugex gafleiq, uqzaqw hyiz vre ekwepsih deqaa oq xop Lene.uqyis ahmvaod ax royc.kikkPiba.yacie.
Ovoam, pof sjo detd, ebx kaa’hx vou cgom ij sitbeikt.
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.