Reputation: 1925
I have my integration tests for a kotlin app in a separate folder like,
src ->
it -> kotlin
-> resources
main -> kotlin
->resources
test -> kotlin
-> resource
I have added the below configurations to my pom.xml for running the integration tests
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<groupId>com.xxx.api</groupId>
<artifactId>my-sort</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-sort</name>
<properties>
<java.version>11</java.version>
<kotlin.version>1.3.31</kotlin.version>
<opentracing-brave.version>0.34.2</opentracing-brave.version>
<reactor.version>3.3.1.RELEASE</reactor.version>
<!-- testing libraries versions-->
<mockk.version>1.9</mockk.version>
<kotlin.junit.version>1.3.41</kotlin.junit.version>
<wiremock.version>2.24.1</wiremock.version>
<jacoco.version>0.8.4</jacoco.version>
<spring-cloud-sleuth.version>2.1.2.RELEASE</spring-cloud-sleuth.version>
<brave.version>5.6.11</brave.version>
</properties>
<build>
<finalName>my-sort</finalName>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/kotlin</source>
<source>src/it/kotlin</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<includes>
<include>/com/xxx/api/**/*</include>
</includes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<!-- change this to the required minimum code coverage -->
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/*IT.kt</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
All the classes for integration tests cases are ending with IT.kt, When ever I ran mvn verify only unit test cases are ran and fail safe report always show
<?xml version="1.0" encoding="UTF-8"?>
<failsafe-summary result="254" timeout="false">
<completed>0</completed>
<errors>0</errors>
<failures>0</failures>
<skipped>0</skipped>
<failureMessage/>
</failsafe-summary>
Upvotes: 1
Views: 908
Reputation: 23252
failsafe
(and also surefire
) internally replace java
-occurrences in the include
-matcher to class
. That means you can't use **/*IT.kt
there, but need to use **/*IT.java
instead (or **/*Test.java
in case of surefire
). Doesn't matter if you really have java-files there.
Another guess is, that you forgot telling the kotlin compiler that it should compile those files under src/it/kotlin
too, i.e.:
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/kotlin</source>
<source>src/it/kotlin</source>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
A bit related: documentation regarding adding Java and Kotlin source folders. In your case it is 2 Kotlin source folders instead of Java and Kotlin folder (that's also the reason why you do not need to overwrite the maven-compiler-plugin
-configuration).
This is the only thing I see which might be missing. The rest should be ok.
Upvotes: 1