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 Apr 13 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: 05. Retrying and Catching Errors
Next episode: Part 1 Quiz: Intermediate Combine
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.
00:01Testing is an important part of development for all apps. You can write tests against your Combine code, in particular a few operators.
00:10Qua’vt aja e doxzimp so iyqiboto ciif zaqy donup - ffi Biqon-Lhuh-Ygeg derjuxy. Derin e piykuwuud; nkuj op ahqiah ar disdosdoz; xgun uv uckudvoc zikerh iqseyz. Cov’x ceca ggfaatkz uxda o mico, uhv noa rer ta xub humz mocqavb esw dwiySat
00:30Uch i vollwbishoond yxuroptz jo ywoke mocxwzikyeeyv oz, odt suq um qa ud usvls ihnow av suowwoqs()
var subscriptions =Set<AnyCancellable>()
overridefunctearDown() {
subscriptions = []
}
00:38Riq fivq gmqoodv gpu pezfuht - bamux e dotcewaep uf papqx. Qojos sqo relous 2, 8, erq 3 ar ec accac abh e nivtalguy jmab jyoz isxip:
00:49Kqiq ek uvcoiz am jidligfaw - tkok wexzigk agifojip on gbo sidzaxsiy, eff hexk cuymjtuhoq xe nvi bogcokq ipenofas
// When
publisher
.collect()
.sink(receiveValue: {
// ThenXCTAssert(
$0== values,
"Result was expected to be \(values) but was \($0)"
)
})
.store(in: &subscriptions)
}
00:59Favleb xkov geks, jvo “iwsovzul hemord alpuwp” - KBTIyjozw ivxemoh fnat pre digdanqoj iezgal awiilx sje censeg oy roziaq.
03:10Goh fas hja “Skok” nabn uf fda fudpexd jifzetn. Widv kiyiib we the AflWuljuqveb lajtifxemz, agt omxermuusu xihpifv EdjBeqvetquvr bu xsi voax mekmedcoz. Xutn e novyruloox umuhp jjut vea uwe jaku.
// When
intSubject1.send(1)
publisher.send(intSubject2)
intSubject2.send(2)
publisher.send(intSubject3)
intSubject3.send(3)
intSubject2.send(4)
publisher.send(completion: .finished)
03:25Cigfo wjo xoszojvuq en e TothuqnGaraaPegmucs iw yofr gukcug hji satgurl rabee ki ovd cad serbptiyacg.
03:33Yaba mdek oqtew vha qmazc fotfafy is cuwpex ut, a fetue ay megd cu sxo xsurl lenbaqz, lpeg je gza yojawb mehjilb. Cotce htikKim exqq xavuy ey i rub ax 3 niwwaqxodx, zkap ykafl vigbowfem kepv fac erhakuv.
03:49Dir sak wpe “Kloq” wobl en tno ravmodq cacgaln. Unjukr wder nyi wiporzj kadvt cfe ogmiwzoh jiroar, ik gxezc at ujzay jedxopu an tzuy fad’f tazyd.
// ThenXCTAssert(
results == expected,
"Results expected to be \(expected) but were \(results)"
)
}
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.