Issue
Our team is making first steps into Kotlin and I'm about to to migrate a test. I tried a first example from mockk (https://github.com/mockk/mockk/blob/master/mockk/common/src/test/kotlin/io/mockk/it/InjectMocksTest.kt). For some reason it seems I'm not able to use kotlin.test although I have added it via maven. Do I have to include any other modules? Or do I have to change something else?
(the mockk example uses Gradle so it doesn't help me).
This is what I'd like to use in my Kotlin test file but it which can't be found (at least not the packages I need):
(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>
Solution
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.
Answered By - hotkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.