You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Provide inputs then test outputs. This is an example code that tests map() operator multiplying the values by 2.
func testMultiply(){lettest=RxExpect()letvalue=PublishSubject<Int>()letresult= value.map{ $0 *2}
// provide inputs
test.input(value,[next(100,1),next(200,2),next(300,3),completed(400)])
// test output
test.assert(result){ events inXCTAssertEqual(events,[next(100,2),next(200,4),next(300,6),completed(400)])}}
It would be easy to understand if you imagine the marble diagram.
time --100-200-300-400 // virtual timeline
value --1---2---3---| // provide inputs
result --2---4---6---| // test these values
This is more complicated example.
finalclassArticleDetailViewModelTests:XCTestCase{func testLikeButtonSelected(){lettest=RxExpect()letviewModel=ArticleDetailViewModel()
test.retain(viewModel) // IMPORTANT: prevent from being disposed while testing
// providing an user input: user tapped like button
test.input(viewModel.likeButtonDidTap,[next(100,Void()),])
// test output: like button become selected
test.assert(viewModel.isLikeButtonSelected){ events inXCTAssertEqual(events.at(100...).elements,[true])}}func testLikeButtonUnselected(){lettest=RxExpect()letviewModel=ArticleDetailViewModel()
test.retain(viewModel) // IMPORTANT: prevent from being disposed while testing
// providing an user input: user tapped like button
test.input(viewModel.likeButtonDidTap,[next(100,Void()),])
// test output: like button become selected
test.assert(viewModel.isLikeButtonSelected){ events inXCTAssertEqual(events.at(100...).elements,[false])}}}