The document discusses using Firebase Remote Config and unit testing with RxSwift. It provides an overview of Firebase Remote Config and how it can be used to store feature flags and master data when backend development is not ready. It also discusses writing unit tests with Quick, Nimble, and SwiftyMocky to mock dependencies and generate test cases that cover A/B testing logic and various scenarios. The document emphasizes the importance of understanding context before implementation, utilizing Firebase Remote Config features, and clarifying what to test to avoid overcomplicating specifications and logic.
13. Unit Testing with Quick + Nimble + SwiftyMocky
Grenerate Mock for Unit test library
Intro of SwiftyMocky // Install SwiftyMocky CLI
$ brew install mint
$ mint install MakeAWishFoundation/SwiftyMocky
👉 Swift Package Manager
👉 Test Target
// MEMO: Mock preparation required for testing
let checkTrendKeywordEnabledUseCase = CheckTrendKeywordEnabledUseCaseMock()
let getTrendKeywordUseCase = GetTrendKeywordUseCaseMock()
// MEMO: Apply Mock to the class under test
let target = TrendKeywordPresenterImpl(
checkTrendKeywordEnabledUseCase: checkTrendKeywordEnabledUseCase,
getTrendKeywordUseCase: getTrendKeywordUseCase
)
// sourcery: AutoMockable
protocol CheckTrendKeywordEnabledUseCase {
func execute() -> Single<Bool>
}
// sourcery: AutoMockable
protocol GetTrendKeywordUseCase {
func execute() -> Single<[TrendKeyword]>
}
// Generate Mock
$ swiftymocky generate
Prepare for Unit test
SwiftyMocky:
https://github.com/MakeAWishFoundation/SwiftyMocky
14. Write carefully with various cases added
Ensuring behavior that includes A / B test logic as much as possible
Test Case Example Test Pattern Strategy
describe("#execute") {
context(“A/B Testing Target & Get Trend Keywords Success.”) {
let checkTrendKeywordEnabled = true
let trendkeywords = … (Test Data Example) …
beforeEach {
checkTrendKeywordEnabledUseCase.given(
.execute(willReturn: Single.just(checkTrendKeywordEnabled))
)
getTrendKeywordUseCase.given(
.execute(willReturn: Single.just(trendkeywords))
)
}
it(“Return Trend Keywords”) {
expect(try! target.fetch().toBlocking().first())
.to(equal(trendkeywords))
}
}
}
① Write Test Quick & Nimble
② Assign Mock & Stub
- A/B Testing Logic → return true
- Business Logic pattern A → return Single<P>
- Common Business Logic → return Single<Q>
Expected Result → return R
Pattern Case A:
- A/B Testing Logic → return false
- Business Logic pattern A → return Single<S>
- Common Business Logic → return Single<Q>
Expected Result → return T
Pattern Case B:
Secure with Unit Test as much as possible