Hi ! I would like to add some unit tests in my Com...
# multiplatform
l
Hi ! I would like to add some unit tests in my Compose MP project generated with the online Wizard. What are the required steps ? (I'm editing on Fleet, but I can use Intellij Idea)
r
The only thing I know is that in Intellij you can simply right click on the class -> Generate -> Tests Or something like that. It will create a Unit test file for you in the right place. You may have to add JUnit as Dependency
l
Thank you : I try right now 😃
r
As far as I remember.
👍 1
l
Unfortunately, I can't use Test annotation in the test source file. It is not recognized.
So is there a universal testing framework for Kotlin Multiplatform ?
m
take a look at this video :

https://youtu.be/tAMu-RPqkok?si=bJQlcN9rKgcCK5bu

l
Thank. I've been trying following his video yesterday, but even with it I don't manage to set up TDD.
The Test annotation from kotlin.test is still not recognized
Also I can't see the arrow buttons on the left of the editor.
IntelliJ IDEA 2024.1.4 (Community Edition) Build #IC-241.18034.62, built on June 20, 2024 Runtime version: 17.0.11+1-b1207.24 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 6.5.0-41-generic GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 4 Registry: ide.experimental.ui=true terminal.new.ui=true Non-Bundled Plugins: org.jetbrains.android (241.17011.79) org.jetbrains.compose.desktop.ide (1.6.2) Kotlin: 241.18034.62-IJ Current Desktop: ubuntu:GNOME
m
have you added the correct kotlin test dependency to your commonTest in build.gradle shared module?
l
These are my project configuration files. I've also synchronized Gradle and added configuration from the repository of the video.
m
everything seems correct
👍 1
did you add test module this way ?
l
I just added the commonTest/kotlin
m
and it still does not recognize the Test annotation?
l
Right : still the same error
image.png
Alt+Enter => the popup just shows add TestNg and create new annotation Test
The registered project dependencies
kotlin-test 2.0.0 has no annotation Test
r
Maybe you first need to write the function syntax so that it knows you want to annotate a function
And you don't have an import statement as I see
l
image.png
Finally I managed
In build.gradle.kts I've added
Copy code
val desktopTest by getting {
            dependencies {
                implementation(compose.desktop.uiTestJUnit4)
                implementation(compose.desktop.currentOs)
            }
        }
and I used desktopTest/kotlin folder instead of commonTest/kotlin
image.png
r
👌
l
I would like to have it set for commonTest, but for sure, as for now, that's enough 😃