[英]Issue with Integration tests in maven
I have my integration tests for a kotlin app in a separate folder like,我在一个单独的文件夹中对 kotlin 应用程序进行了集成测试,例如,
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我已将以下配置添加到我的 pom.xml 以运行集成测试
<?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集成测试用例的所有类都以 IT.kt 结尾,当我运行 mvn verify 时只运行单元测试用例并且故障安全报告总是显示
<?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>
failsafe
(and also surefire
) internally replace java
-occurrences in the include
-matcher to class
. failsafe
(和也surefire
)内部取代java
-occurrences在include
-matcher到class
。 That means you can't use **/*IT.kt
there, but need to use **/*IT.java
instead (or **/*Test.java
in case of surefire
).这意味着你不能使用**/*IT.kt
有,但需要使用**/*IT.java
代替(或**/*Test.java
中的情况下, surefire
)。 Doesn't matter if you really have java-files there.如果你真的在那里有 java 文件并不重要。
Another guess is, that you forgot telling the kotlin compiler that it should compile those files under src/it/kotlin
too, ie:另一个猜测是,您忘记告诉 kotlin 编译器它也应该编译src/it/kotlin
下的这些文件,即:
<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 .有点相关: 有关添加 Java 和 Kotlin 源文件夹的文档。 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).在您的情况下,它是 2 个 Kotlin 源文件夹,而不是 Java 和 Kotlin 文件夹(这也是您不需要覆盖maven-compiler-plugin
)。
This is the only thing I see which might be missing.这是我看到的唯一可能丢失的东西。 The rest should be ok.其余应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.