Running Kotlin JUnit tests

Answered

I have a project with mixed Java and Kotlin classes, and I figured I would unit test my Kotlin classes using Kotlin.

I’ve created a new Kotlin test class, but can’t figure out how to actually run it. It doesn’t run when I run all the tests in the project. I can’t seem to create a new JUnit run configuration pointing to the class.

import org.junit.Assert
import org.junit.Test

class CsrfFilterTest

@Test
fun simpleTest() {
Assert.assertEquals(2, 1 + 1)
}

How can I get IDEA run this? Any pointers?

3 comments
Comment actions Permalink

Hi Tobin,

I think that IDEA doesn't support top level test functions, please try to place it to the class (adding "{}"). 

Anna

1
Comment actions Permalink

My pom.xml has the following in it…

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
0
Comment actions Permalink

Oh man, so stupid. I didn’t even think about that since there weren’t any compilation errors or anything thing.

 

Thanks!

0

Please sign in to leave a comment.