Home > OS >  How to include kotlin.test properly via Maven?
How to include kotlin.test properly via Maven?

Time:06-29

Our team is making first steps into Kotlin and I'm about to to migrate a test. I tried a first example from mockk (enter image description here

(Restarting Intellij doesn't help, neither running mvn seperately)

This is my maven dependancy (Intellij shows now error):

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-test</artifactId>
    <version>${kotlin.version}</version> <!-- kotlin.version == 1.7.0 -->
    <scope>test</scope>
</dependency>

The solution was (see hotkey's answer) to add the following maven dependency:

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-test-junit5</artifactId>
    <version>1.7.0</version>
    <scope>test</scope>
</dependency>

CodePudding user response:

You need to add a dependency on one of kotlin-test-junit (for JUnit 4), kotlin-test-junit5 (for JUnit Jupiter), or kotlin-test-testng (for TestNG), depending on what test framework you are using.

The artifact kotlin-test contains only the common code, asserters and other stuff that can be reused across the frameworks.

The kotlin.test annotations like @Test or @BeforeTest are shipped in the test-framework-specific artifacts as typealiases to the actual annotations types of the test frameworks.

  • Related