Testing
Testing strategy and practices for the Meshtastic KMP project.
Test categories
KMP unit tests (commonTest)
Shared tests written once and run on the JVM and, in modules that declare withHostTest, as Android host tests. commonTest also compiles for iOS, but iOS test execution is disabled, so no iOS test runs. In modules that apply meshtastic.kmp.web, it also runs in headless Chrome, except where a module sets meshtasticWeb { browserTests = false } (feature:node, feature:settings), whose wasmJs tests only compile:
./gradlew allTests
# the web target: needs Isolated Projects off
./gradlew wasmJsBrowserTest -Pmeshtastic.web=true -Dorg.gradle.isolated-projects=false
- Business logic tests
- Data model validation
- Search/ranking algorithm tests
- Route serialization tests
Android host tests
Android-specific tests that run on the JVM. In pure-Android/JVM modules (such as androidApp) test runs them; in KMP modules that declare withHostTest {}, allTests runs them through testAndroidHostTest:
./gradlew test # pure Android/JVM modules
./gradlew allTests # KMP modules
- 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 (layoutlib) screenshot testing framework, split across two modules:
:screenshot-tests— the visual-regression gate. CI runsvalidateDebugScreenshotTeston it; reframing one of these baselines is a real diff to review. Holds atomic, dual-purpose components.:docs-screenshots— generate-only, not validated in CI. Holds doc-framed compositions whose framing is tuned for the docs site, so reframing a doc image never churns the regression gate.
./gradlew :screenshot-tests:updateDebugScreenshotTest -Dorg.gradle.isolated-projects=false # record regression goldens
./gradlew :screenshot-tests:validateDebugScreenshotTest -Dorg.gradle.isolated-projects=false # compare against goldens (CI gate)
./gradlew :docs-screenshots:updateDebugScreenshotTest -Dorg.gradle.isolated-projects=false # record doc-framed composition images
./gradlew :screenshot-tests:copyDocsScreenshots # copy doc images from BOTH modules into docs/assets
The update and validate tasks need -Dorg.gradle.isolated-projects=false: the screenshot plugin fails under Isolated Projects after it has rendered. Run copyDocsScreenshots as its own command after the updates, because Gradle doesn’t order it behind them.
The images under docs/assets/screenshots/ are copies of these references. scripts/check-docs-screenshots.sh, a docs-quality.yml gate, fails a pull request whose reference and copy differ, so a change that re-records a reference also commits what copyDocsScreenshots writes.
Rendering runs on the host through layoutlib, so goldens recorded locally are the ones CI validates against. validate allows an image-difference threshold of 0.0005, set in AndroidScreenshotConventionPlugin, because pixel-exact comparison fails some references. See docs/assets/screenshots/README.md for which module a new screenshot belongs in.
Store screenshots
The store-listing screenshots (Play, F-Droid, IzzyOnDroid, and the desktop app’s Flathub listing) are taken from the real apps, connected to Demo Mode’s hidden showcase mesh (/connections?address=mshowcase, MockScenario.SHOWCASE in :core:data), rather than drawn. Every screen is reached by its deep link, so the flow does not depend on the display language, and each shot is kept once the window has stopped changing.
- Android:
:store-screenshots, a UiAutomator 2.4 test module targeting:androidApp. For each surfacefastlane supplyuploads it sets the display size and density, relaunches the debug app through its shell-onlyAutomationLauncheralias withskip_onboardingandskip_connect_confirm, and saves the five listing shots, full screen with a SystemUI demo-mode status bar, to/data/local/tmp/store-screenshots/<flavor>on the device. - Desktop:
store-screenshots/capture-desktop.shruns the real desktop debug build on an Xvfb display, one launch per screen with that screen’s deep link, and saves the five Flathub shots. The map needs Skiko’s OpenGL renderer and Skiko refuses any GL adapter namedllvmpipeorvirgl, so Mesa runs GL through zink over lavapipe.
On an emulator or device, one flavor at a time:
./gradlew :store-screenshots:connectedFdroidDebugAndroidTest
adb pull /data/local/tmp/store-screenshots/fdroid/. fastlane/metadata/android/en-US/images/
| Folder | Size | Window | Uploaded by |
|---|---|---|---|
phoneScreenshots/ | 1080×1920 @400 dpi | compact: bottom navigation bar | fastlane supply |
sevenInchScreenshots/ | 1080×1920 @288 dpi | medium: navigation rail, one pane | fastlane supply |
tenInchScreenshots/ | 2560×1440 @320 dpi | expanded: rail, list beside detail | fastlane supply |
tvScreenshots/ | 1920×1080 @320 dpi | TV mode (D-pad), google flavor on an Android TV image only | fastlane supply |
tvBanner.png (committed, 1280×720) | 1280×720 | the launcher banner | fastlane supply |
desktopApp/packaging/linux/screenshots/ | 1280×800 | expanded: rail, list beside detail | Flathub, through the release assets metainfo.xml names |
.github/workflows/store-screenshots.yml runs both on hosted runners, each Android flavor in its own job on its own emulator through store-screenshots/capture-android.sh (google for the Play listing, fdroid for the committed tree), plus a google-tv job on an Android TV image (capture-android.sh google out tv, the formFactors instrumentation argument) because TV mode keys off FEATURE_LEANBACK, on every internal release, on demand, and on pull requests that touch the renderer or the showcase mesh. The release pipeline attaches the captures to the release, publishes the Play listing from them on production, and opens a self-merging PR that writes the fdroid and desktop sets back here (RELEASE_PROCESS.md).
Baseline Profile / startup performance
The :baselineprofile module (#5735) generates a Baseline Profile for :androidApp, AOT-compiling the hot startup paths so ART doesn’t pay the JIT cost on first launch. It profiles the google flavor (the variant most users run), and both flavors ship the result.
The Macrobenchmark generator (BaselineProfileGenerator) and the before/after benchmark (StartupBenchmark) live in baselineprofile/src/main/kotlin/org/meshtastic/baselineprofile/. Both run on a device/emulator:
./gradlew :androidApp:generateBaselineProfile # Generate the profile (commit the output)
./gradlew :baselineprofile:connectedGoogleBenchmarkReleaseAndroidTest # Quantify the cold-start win
The generated profile is merged into androidApp/src/main/generated/baselineProfiles/ (mergeIntoMain in androidApp/build.gradle.kts), so the fdroid and google release builds both package it via androidx.profileinstaller. scheduled-baseline.yml regenerates it daily on an emulator and opens a pull request when it changes.
ℹ️ Note: The journey covers cold start only (launch → first frame), because the harness connects to no node. Post-connection screens (node list, map, message thread) aren’t AOT-compiled.
Extending the journey past cold start needs the harness to connect to a node, the way :store-screenshots connects to Demo Mode’s showcase mesh.
SDK session tests
core:data’s JVM tests drive the meshtastic-sdk session the app runs on every link. They replay the two-stage PhoneAPI handshake and use a loopback TCP peer to check the session stream, the Room snapshot, the NodeDB refresh and stale-session rejection. SdkTcpRoomTest can run its snapshot test against a real radio: set MESHTASTIC_SDK_TCP_HOST (and MESHTASTIC_SDK_TCP_PORT, 4403 by default) and add --rerun --no-build-cache so Gradle does not replay a cached result.
To build against a local SDK checkout instead of the published artifacts, pass -PmeshtasticSdkCheckout; settings.gradle.kts then substitutes the checkout’s modules for the org.meshtastic:sdk-* dependencies:
./gradlew :core:data:jvmTest :androidApp:assembleFdroidDebug \
-PmeshtasticSdkCheckout=/absolute/path/to/meshtastic-sdk \
-Dorg.gradle.isolated-projects=false --no-configuration-cache
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 on the JVM, and as an Android host test where the module declareswithHostTest) - 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 tests: allTests covers KMP modules, test covers Android/JVM-only modules; run both
./gradlew test allTests
# Specific module
./gradlew :feature:docs:allTests
# Code quality
./gradlew spotlessCheck detekt detektTypeResolved
# Full verification
./gradlew spotlessCheck detekt detektTypeResolved assembleDebug kmpSmokeCompile test allTests
CI integration
Tests run automatically on:
- Pull requests whose changes match the
androidordesktoppath filter (pull-request.yml) - The merge queue (
merge-queue.yml) - Pushes to
main(main-check.yml)
Each of these calls reusable-check.yml. The test shards compile with -PwarningsAsErrors=true, so a Kotlin warning that passes a local build fails CI unless you pass the same flag.
A pull request whose changes match the web path filter also runs web-check in pull-request.yml: wasmJsBrowserTest and the production :webApp link. The merge queue never builds the web target; on main only web-snapshot.yml does, to deploy app-snapshot.meshtastic.org.
On a pull request into main, Develocity Predictive Test Selection runs only the jvmTest tests it predicts the change can affect. Pull requests into release/**, the merge queue, main and local runs execute every test. On a pull request build-desktop runs proguardReleaseJars on ubuntu-24.04 only, and main runs it on every OS.
Single-runner jobs in reusable-check.yml run on the pinned Ubuntu LTS x64 label with JDK 25 and Gradle caching. Two jobs use a matrix: test-shards splits into shard-core, shard-feature and shard-app, and build-desktop runs across macOS, Windows and Linux x64 and arm64, on the labels its own matrix lists. Flatpak verification is its own workflow, not a job here. The pinned Ubuntu LTS arm label and the container-backed ubuntu-slim runners carry the lightweight jobs. .skills/testing-ci/SKILL.md has the four-tier rule.