Testing subscriptions on Compose Multiplatform: one test suite for iOS and Android
Blog post from RevenueCat
The article explores a comprehensive approach to subscription testing for a Compose Multiplatform app, focusing on overcoming the challenge of managing two separate sandbox environments for Google Play and StoreKit. It introduces RevenueCat's Test Store as a unified sandbox solution, which simplifies the testing process by eliminating the need for two parallel test suites and allows for consistent testing across platforms. The testing strategy is structured into three layers: unit tests in commonTest using a FakePaywallsRepository, integration tests with instrumented tests via Espresso on Android and XCUITest on iOS, and optional platform-specific tests for native edge cases. This method ensures that the same code path is tested end-to-end, enhancing efficiency and reducing fragmentation. By placing a PaywallsRepository interface between Purchases.sharedInstance and the rest of the app, and using fakes instead of mocks, the setup supports cross-platform testing seamlessly, making it suitable for both new projects and those transitioning from Android to iOS.