JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.21k stars 1.17k forks source link

Add an example/tutorial of using unit tests #368

Closed igordmn closed 1 year ago

igordmn commented 3 years ago

Also we need to add uiTestJUnit4 to gradle plugin:

    object Dependencies {
        val desktop = DesktopDependencies
        val animation get() = composeDependency("org.jetbrains.compose.animation:animation")
        val foundation get() = composeDependency("org.jetbrains.compose.foundation:foundation")
        val material get() = composeDependency("org.jetbrains.compose.material:material")
        val runtime get() = composeDependency("org.jetbrains.compose.runtime:runtime")
        val ui get() = composeDependency("org.jetbrains.compose.ui:ui")
        val materialIconsExtended get() = composeDependency("org.jetbrains.compose.material:material-icons-extended")
        val uiTestJUnit4 get() = composeDependency("org.jetbrains.compose.ui:ui-test-junit4")
    }
igordmn commented 3 years ago

For now we can use this in build.gradle.kts:

dependencies {
    testImplementation(compose("org.jetbrains.compose.ui:ui-test-junit4"))
}

Example of unit test

igordmn commented 3 years ago

Also we need to add docs how to do screenshot-based testing:

val window = TestComposeWindow(width = 1024, height = 768)
window.setContent {

}
File(path).writeBytes(window.surface.makeImageSnapshot().encodeToData()!!.bytes)
igordmn commented 3 years ago

We should also add an important note about JUnit version: createComposeRule only works with JUnit 4.

tylergannon commented 2 years ago

Hi all! Would appreciate any notes at all, on how to get started setting up multiplatform tests using the above mentioned library.

m-sasha commented 1 year ago

Added an example to both the compose multiplatform desktop template, and the imageviewer example project. Do we need anything else here, @igordmn?

igordmn commented 1 year ago

Added an example to both the compose multiplatform desktop template, and the imageviewer example project. Do we need anything else here, @igordmn?

We can close the issue after we add a doc and merge everything to master.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.