Banksalad Removes iOS Unit Test Boilerplate with RxTestCase and BaseTestCase
Key point
Banksalad's iOS team unveiled a strategy that uses the TestUtility module to reduce boilerplate in RxSwift-based unit tests and expand TDD coverage.
Details
Banksalad's iOS development team unveiled an approach that leverages the TestUtility module to ensure simplicity and consistency in unit tests. The core tool, BaseTestCase, provides a given, when, then structure, and RxTestCase inherits from it to internally manage TestScheduler, DisposeBag, and resultObserver for testing RxSwift-based asynchronous logic.
When the eventsToObserve property is set, RxTestCase automatically initializes and binds the related objects, and in the when method, it calls executeEvents after executing input events to accumulate results. This significantly reduces TestScheduler-related boilerplate code, allowing test code to be written in around 3 lines.
For verifying logging specs, EventLoggingTestCase was implemented separately. By initializing EventLogger's eventObserver property as a PublishSubject, whether an event was logged becomes observable from test code, improving the reliability of logging logic that is difficult to verify visually. In addition, PresentationTestCase and PushableLogicTestCase are used for testing screen transition logic, performing integration tests that connect Form inputs with screen transition outputs.
To solve the Equatable issue when comparing screen output values managed as enums, Banksalad declared debugDescription. To prevent burnout when applying TDD, the team suggests starting with relatively easy areas such as EventLogging or Navigation logic and gradually expanding coverage, using automated tests as living, breathing spec documentation.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.