You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To write JUnit tests in Kotlin it is recommended to include testImplementation(kotlin("test")), i.e. the kotlin-test dependency.
Tests work without that, but fallback to the default implmentation for assertions instead of using the JUnit implementation, as I learned here: https://youtrack.jetbrains.com/issue/KT-50260
Normally, kotlin-test delegates assertions like equality to the assertion API of an underlying testing framework, and the default implementation is used only as a last resort. To enable such delegation on JVM you need to ensure that you have a dependency on either kotlin-test-junit, or kotlin-test-junit5, or kotlin-test-testng.
Note that in Gradle, the Kotlin plugin can determine automatically which flavor of kotlin-test dependency to use based on the test runner used in a project.
I was surprised that I had to add testImplementation(kotlin("test")) myself, and it wasn't added in Spring initializer projects. What do you think?
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion, @darioseidl. We'll want to do the same for a Kotlin project built with Maven. AIUI, kotlin("test") maps to org.jetbrains.kotlin:kotlin-test-junit5 when using JUnit 5. It may be easier to add this dependency directly as that'll work with either build system.
wilkinsona
changed the title
Kotlin projects should include testImplementation(kotlin("test"))
Kotlin projects should automatically depend on org.jetbrains.kotlin:kotlin-test-junit5
Jan 21, 2022
To write JUnit tests in Kotlin it is recommended to include
testImplementation(kotlin("test"))
, i.e. thekotlin-test
dependency.Tests work without that, but fallback to the default implmentation for assertions instead of using the JUnit implementation, as I learned here:
https://youtrack.jetbrains.com/issue/KT-50260
I was surprised that I had to add
testImplementation(kotlin("test"))
myself, and it wasn't added in Spring initializer projects. What do you think?The text was updated successfully, but these errors were encountered: