Testing¶
Test Structure¶
| Type | Location | Runner |
|---|---|---|
| Unit tests | mobile/src/test/ |
JUnit 4 + Robolectric |
| Instrumentation tests | mobile/src/androidTest/ |
AndroidJUnitRunner |
Running Tests¶
Unit Tests¶
# Run all mobile unit tests (debug variant)
./gradlew :mobile:testDebugUnitTest
# Run all tests for all modules
./gradlew test
# Run a specific test class
./gradlew :mobile:testDebugUnitTest --tests "com.shelbeely.opentransition.HomeDomainTest"
Test reports are generated at:
Instrumentation Tests¶
Requires a connected device or running emulator:
Reports at:
Lint¶
Reports at:
Testing RxJava Code¶
Use RxJava TestObserver and TestScheduler to control timing:
val testObserver = domain.state.test()
domain.loadPhotos()
testObserver.assertValue { it is HomeState.Success }
Use androidx.arch.core:core-testing for InstantTaskExecutorRule when testing LiveData.
Testing Room Database¶
Use an in-memory Room database in unit/instrumented tests:
val db = Room.inMemoryDatabaseBuilder(
InstrumentationRegistry.getInstrumentation().context,
AppDatabase::class.java
).build()
Testing Encrypted Database¶
- Enable in
SettingsManagerbefore callingDatabaseManager.getDatabase() - Create test data
- Close and reopen the database instance
- Verify data persists and is not readable as plaintext
CI¶
Unit tests run automatically on every PR via the pr-debug.yml GitHub Actions workflow. See CI/CD for details.