1

I've been struggling for a while now trying to get kotlintest tests to run properly from maven. I'm far from a maven expert so I'm hoping someone can tell me where I'm going wrong.

I started with the maven example from the kotlin repo here, and that works fine. The issue arises when more tests are added. When I add more tests (in nested packages), only a single test actually gets "run", the others just seem to have a dummy test method run. For example, given the following hierarchy:

project structure

With this pom.xml, running mvn test gives:

Running BarTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec <<< FAILURE! - in BarTest
should fail  Time elapsed: 0.004 sec  <<< FAILURE!
java.lang.AssertionError: expected: true but was: false
Running test.BarTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.01 sec - in test.BarTest
Running a.AThingTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in a.AThingTest
Running newtest.FooTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in newtest.FooTest

Results :

Failed tests:
  BarTest expected: true but was: false

Tests run: 5, Failures: 1, Errors: 0, Skipped: 0

The very first one: Running BarTest is actually the right test (and has an intentional failure). All the other ones (Running test.BarTest, Running a.AThingTest, Running newtest.FooTest) aren't actually running my tests (I have intentional failures there too), and appear to be just some dummy tests (perhaps from the dummy @Test in IntelliTestMarker?). I included a sample of one of those test files below.

What do I need to do to run all of my actual tests? And, preferably, not have the 'dummy' tests show up in the output?

BarTest.kt:

package test

import io.kotlintest.shouldBe
import io.kotlintest.specs.ShouldSpec

class BarTest : ShouldSpec() {
    init {
        "Bar" {
            should("succeed") {
                true shouldBe true
            }
            should("fail") {
                false shouldBe true
            }
        }
    }
}
bbaldino
  • 394
  • 3
  • 15

1 Answers1

1

The answer is embarrassingly quite simple. Upgrade to 3.0.3. This was a bug in 3.0.0 to 3.0.2 that affected Maven builds.

For the sake of completeness here are the full maven project instructions for KotlinTest 3.0.x

Add this dependency to your <dependencies> section.

    <dependency>
        <groupId>io.kotlintest</groupId>
        <artifactId>kotlintest-runner-junit5</artifactId>
        <version>3.0.3</version>
        <scope>test</scope>
    </dependency>

Make sure you add the surefire plugin to your <build><plugins> section and with it add the jUnit platform surefire provider.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.1.0</version>
                </dependency>
            </dependencies>
        </plugin>

Note: There is a bug with jUnit platform and surefire plugin 2.20.0 so stick with 2.19.1 for now.

Here is the complete project on the KotlinTest website: https://github.com/kotlintest/kotlintest/tree/master/kotlintest-samples/kotlintest-samples-maven

sksamuel
  • 16,154
  • 8
  • 60
  • 108