Spek tests not being run in a maven Java project

278 views Asked by At

I have an existing Java project in which I wish to introduce some Spec tests (in kotlin ofc)

class CalcSpec: Spek({
    given("A calculator") {
        val calculator = Calculator()
        on("Adding 3 and 5") {
            val result = calculator.sum(3, 5)
            it("Produces 8") {
                org.junit.jupiter.api.Assertions.assertEquals(8, result)
            }
        }
    }
})

I have added the spek dependencies

        <dependency>
            <groupId>org.jetbrains.spek</groupId>
            <artifactId>spek-api</artifactId>
            <version>1.1.5</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jetbrains.spek</groupId>
            <artifactId>spek-junit-platform-engine</artifactId>
            <version>1.1.5</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>

And configured the kotlin-maven-plugin and maven-compiler-plugin as descibed here https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources
(ommiting the maven-compiler-plugin config from the question)

       <build>
        <plugins>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <version>1.0.6</version>
            <executions>
                <execution>
                    <id>test-compile</id>
                    <phase>process-test-sources</phase>
                    <goals> <goal>test-compile</goal> </goals>
                    <configuration>
                        <sourceDirs>
                            <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
                        </sourceDirs>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <useManifestOnlyJar>false</useManifestOnlyJar>
                <includes>
                    <include>**/*Spec.*</include>
                </includes>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.0</version>
                </dependency>
            </dependencies>
        </plugin>
       ...
    </plugins>
</build>

I have tried different versions of kotlin, spek, and the surefire plugin but with no luck until now.

Every time I try to run the tests no Spek tests are being executed, even though they are in target/test-classes. (for the CalcSpec there are 5 .class files generated)

1

There are 1 answers

1
EJG On

I know you've said that you have tried different versions but try surefire 2.19 and Junit-platform 1.1.0-M2.

I had this same issue a while ago, and those worked for me.