This project is an Android application built using Jetpack Compose and Clean Architecture principles.
It includes unit test cases for different layers and demonstrates how Gradle automatically generates test reports in HTML format.
Flavours implemented: staging and production.
- Jetpack Compose for UI
- Clean Architecture (data, domain, presentation layers)
- Unit tests for data and domain layer logic
- Gradle test reports viewable in a web browser
- Flavour-based builds: staging and production
- Release build automatically runs unit tests before generating the bundle
You can still configure Gradle to run unit tests automatically before creating a release build.
This helps prevent releasing builds with broken code.
Add the following to your app/build.gradle.kts:
afterEvaluate {
android.applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
val variantName = variant.name.replaceFirstChar { it.uppercaseChar() }
val bundleTaskName = "bundle${variantName}"
val testTaskName = "test${variantName}UnitTest"
tasks.named(bundleTaskName) {
dependsOn(testTaskName)
}
}
true
}
// To view the unit test report:
// Open: app/build/reports/tests/test${variantName}UnitTest/index.html
}- Clone this project:
git clone https://github.com/collatzinc/AndroidUnitTesting.git
- Open the project in Android Studio.
- Run the unit tests:
- Locate the test report:
Replace
app/build/reports/tests/test${variantName}UnitTest/index.html${variantName}with your build variant, for example:StagingDebugProductionRelease
- Open the HTML file in your preferred web browser to see the results.