Skip to content

TouhidApps/Unit-Test-Kotlin-Multiplatform-Compose

Repository files navigation

Unit Test Kotlin Multiplatform Compose

Exmaple of Unit Test - Kotlin Multiplatform Compose

UI Unit test and Kotlin unit test

Unit test setup guide for Kotlin Multiplatform Compose

Kotlin Multiplatform Compose Unit test Kotlin Multiplatform Compose Unit test Kotlin Multiplatform Compose Unit test Kotlin Multiplatform Compose Unit test Kotlin Multiplatform Compose Unit test

To set and see test coverage:

Add below plugin:

id("org.jetbrains.kotlinx.kover") version "0.8.0"

Set below rule: If test meets the cover rule test will pass otherwise failed: Ex:

kover {
    reports {
        verify {
            rule {
                /**
                 * If 10% code is executed in test it should pass, otherwise failed
                 * You can set it 80 if you can write that much unit test code
                 */
                minBound(10)
            }
        }
        filters {  // To get clean report we should filter unwanted packages/classes
            excludes {
                // Entry points
                classes("MainKt") // Desktop
                classes("*.MainActivity") // Android

                // Generated classes and resources
                packages("*.generated.*")
                packages("*.di*") // Dependency injection package

                // Compose related(If you don't do UI testing)
                classes("*ComposableSingletons*")
                annotatedBy("androidx.compose.runtime.Composable")
                annotatedBy("androidx.compose.ui.tooling.preview.Preview")

                classes("CounterKtTest") // For this project this is for UI testing
            }
        }
    }
}

Run kover from terminal:

./gradlew koverVerify -> Run all test and see error/exception in html page
./gradlew koverHtmlReport -> Get test report in html page to see how much code are covered by test

If failed it will show an html link in terminal about code coverage info.

AAA Pattern: Arrange, Act, Assert

Test Class: CalculatorTest

Function Class: MyCalculator

Kotlin Multiplatform Compose kover

About

Unit Test - Kotlin Multiplatform Compose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published