Badoo Arkadii Ivanov Jul 28, 2020

MVI Architecture in Kotlin Multiplatform - Part 3

Article Summary

Arkadii Ivanov from Bumble Tech tackles the biggest challenge in Kotlin Multiplatform testing: no mocking frameworks. His solution? Embrace it as a feature, not a bug.

This is the final part of a three-part series on implementing MVI architecture in Kotlin Multiplatform. Ivanov covers the Kittens module with comprehensive unit and integration tests, demonstrating how to test shared code that runs on both iOS and Android without traditional mocking tools.

Key Takeaways

Critical Insight

Writing test implementations instead of using mocks creates more maintainable code that automatically validates against platform-specific quirks like Kotlin/Native's memory model.

The article includes two bonus exercises that will change how you think about dependency abstraction and test design in cross-platform projects.

About This Article

Problem

Kotlin Multiplatform doesn't have mocking frameworks for Kotlin/Native and Kotlin/JS. Developers end up manually creating interfaces for every dependency and writing test implementations instead of using mocks.

Solution

Arkadii Ivanov's team worked with this constraint by building fake implementations like TestKittenStoreNetwork and TestKittenDataSource. They encoded responses in common formats and used TestScheduler to freeze callbacks, which let them verify Kotlin/Native memory model compatibility without needing multithreading.

Impact

The Kittens module got comprehensive test coverage across all targets with unit and integration tests that run fast and don't flake. When the code changed later, updates took much less time because the tests weren't tied to mock specifications.