Is it possible to write unit tests for a Compose D...
# compose-desktop
m
Is it possible to write unit tests for a Compose Desktop project? If so, is there any “getting started” page somewhere to help?
j
What are you trying to test? Compose logic (no UI)? A UI function? A whole screen?
m
I want to test the UI. Logic shouldn’t be a problem to test
I want to test the UI kind of like Selenide would test a web page as a user would type and click the mouse.
j
Got it. I personally have no idea if any libraries have made it to Desktop for this or not. In general, the one on Android operates on the semantics tree which is also the place where accessibility information lives. So you can wait for items to appear, parse the semantics of items (their text, image descriptions, etc.), and then perform interactions on the equivalent node (type, touch, etc.).
m
Thanks. I’ll check that out. This looks like a good, quick video to cover the basics:

https://www.youtube.com/watch?v=JyUJZvJ-OV8

I tried doing a basic test but I’m getting this error:
Unresolved reference: createComposeRule
caused by adding this to a new test class:
Copy code
@get:Rule
val rule = createComposeRule()
the relevant section of my build.gradle.kt looks like this, but I feel like I’m copying various suggestions from the web and getting nowhere. I think some official docs on this would be beneficial, but maybe testing is not ready yet?
Copy code
val jvmTest by getting {
    dependencies {
        implementation(kotlin("test-junit"))
        implementation("junit:junit:4.13.2")
    }
}
m
Did you add the dependencies mentioned at 0:40 of that video?
m
Yes, I tried adding those but just get these errors, which is why I tried to find an answer in google:
Unresolved reference: androidTestImplementation
Unresolved reference: debugImplementation
This is the code for my project here (just started): https://github.com/mfearby/Magnificat
a
m
There’s definitely a lot more going on in his build.gradle compared to mine, so I’ll check it out. Thank you.
This is what I needed in my jvmTest dependencies to successfully import the necessaries for `createComposeRule()`:
Copy code
implementation("org.jetbrains.compose.ui:ui-test-junit4:1.2.1")
361 Views