Kotlin (JS) and unit-testing


Hi there!

We have written two rich GUI applications using Kotlin and in-house web framework. So far we have managed without writing any unit-tests (thanks to the fact that Kotlin is such a great language), but they are sometimes greatly missed.

Is there anyone who knows a way to unit-test Kotlin code, without writing the tests in pure JS against Kotlin-generated JS?


For sure you can use Karma and kotlin’s built-in qunit support. Works well with Maven 1.0.x and gradle plugin 1.1 latest snapshots. Which one do you use?


Hi Sergey and thanks for a promising answer :slight_smile:

I’m using Maven 3 and the kotlin-maven-plugin and Kotlin 1.0.5.

Do you mean that this only works with upcoming Kotlin 1.1?


Is there any examples of how to do this? I’ve been looking around without finding any.


Yes, there is. See here: https://github.com/Kotlin/kotlinx.html/tree/master/js

It works with 1.0.x as well


Thanks so much! I will look at it soon.


Hi again! I’ve now finally started to test this out.

I’m now using Kotlin 1.0.6

I’ve created test code under src/test/kotlin and have karma setup files in src/test/karma, as in your kotlinx project.

The tests run, when I use maven, however when I try to compile the project through intelliJ, then the compiler does not recognise references to code in src/main/kotlin (production code) in the src/test/kotlin (test code).

Would you know what’s wrong? Known problem?

I also noticed that you’re kotlinx project does not compile in IntelliJ either (only using maven). Is that a known problem too? Or a setup problem on my side?



After struggling a lot with this (and not owning IntelliJ Ultimate Edition, so I can’t use test-runners like Karma), I finally gave up and made a very hacky solution: I now use a Junit5 dynamic test that calls qunit-cls on the compiled tests and parses it’s output:


Here is a working example using IntelliJ community + Gradle + QUnit:

Here is a working example using IntelliJ community + Maven + JUnit and QUnit: