Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin projects should automatically depend on org.jetbrains.kotlin:kotlin-test-junit5 #1297

Closed
darioseidl opened this issue Jan 19, 2022 · 1 comment
Assignees
Milestone

Comments

@darioseidl
Copy link

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 19, 2022
@wilkinsona
Copy link
Contributor

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 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
@mhalbritter mhalbritter added type: enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 1, 2024
@mhalbritter mhalbritter self-assigned this Jun 5, 2024
@mhalbritter mhalbritter added this to the 0.21.0 milestone Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants