Testing
Testing strategy and practices for the Meshtastic KMP project.
Test Categories
KMP Unit Tests (commonTest)
Shared tests that run on all platforms:
./gradlew allTests
- Business logic tests
- Data model validation
- Search/ranking algorithm tests
- Route serialization tests
Android Host Tests
Android-specific tests that run on JVM:
./gradlew test
- ViewModel tests
- Repository tests with Room fakes
- Android-specific integration tests
Compose UI Tests
Compose Multiplatform UI test framework:
@Test
fun myScreenTest() = runComposeUiTest {
setContent { MyScreen() }
onNodeWithText("Expected").assertIsDisplayed()
}
Located in commonTest or jvmTest source sets.
Screenshot Tests
Uses Android Gradle Pluginβs native screenshot testing framework:
./gradlew :screenshot-tests:updateDebugScreenshotTest # Record golden images
./gradlew :screenshot-tests:validateDebugScreenshotTest # Compare against goldens
./gradlew :screenshot-tests:copyDocsScreenshots # Copy reference images to docs pipeline
Test Organization
feature/my-feature/src/
βββ commonTest/kotlin/org/meshtastic/feature/myfeature/
β βββ MyBusinessLogicTest.kt
β βββ MyModelTest.kt
βββ jvmTest/kotlin/org/meshtastic/feature/myfeature/
βββ MyDesktopSpecificTest.kt
Testing Guidelines
DO
- Write tests in
commonTestwhen possible (runs everywhere) - Test business logic independently from UI
- Use fakes/stubs instead of mocks where practical
- Test edge cases: empty states, error states, boundary values
- Test deep link routing in
DeepLinkRouterTest - Keep tests fast β no network, no disk I/O in unit tests
DONβT
- Donβt test framework behavior (Compose internals, Room queries)
- Donβt create tests that depend on other feature modules
- Donβt use
Thread.sleepβ use coroutine test dispatchers - Donβt rely on test execution order
Running Tests
# All KMP tests
./gradlew allTests
# Specific module
./gradlew :feature:docs:allTests
# Code quality
./gradlew spotlessCheck detekt
# Full verification
./gradlew spotlessCheck detekt kmpSmokeCompile test allTests
CI Integration
Tests run automatically on:
- Pull request creation/update
- Push to
main - Pre-release validation
The CI workflow uses ubuntu-24.04 with JDK 21 and Gradle caching.