我的Maven构建包括单元和集成测试执行,作为两个独立的配置文件与Jacoco进行代码覆盖
我在使用 failsafe 插件时遇到了一些问题,并且需要一个方向来寻找解决方案。我已经通过大量可用的内容进行了讨论,但还是无法解决问题。
<environmentVariables>
不适用于故障安全,而它确实可以使用。我尝试了<systemProperties>
,<systenPropertiesVariables>
,<properties>
的所有内容;但似乎没有人为我的Integrations测试用例设置环境变量。<excludes>
的测试用例排除对故障安全无效;它确实在哪里。我的故障安全配置是:
<profile>
<id>it-coverage</id>
<build>
<plugins>
<!-- MAVEN Failsafe plugin. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<environmentVariables>
<config>config/preferences.xml</config>
<log4jproperties>config/log4j.properties</log4jproperties>
<jacoco-agent.destfile>target/it-jacoco.exec</jacoco-agent.destfile>
</environmentVariables>
<excludes>
<exclude>**/*UTest.java</exclude>
</excludes>
<includes>
<include>**/*ITest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
答案 0 :(得分:0)
好吧,我的问题已经解决了。 我将 surefire-plugin 添加到我的集成配置文件以及 failsafe-plugin ,一切都开始落实到位。
以下是适合我的配置。
<profile>
<id>it-coverage</id>
<build>
<plugins>
<!-- MAVEN Failsafe plugin. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${failsafeArgLine}</argLine>
<systemPropertyVariables>
<config>${config.preferences}</config>
<log4jproperties>${config.log4jproperties}</log4jproperties>
<!-- <jacoco-agent.destfile>target/it-jacoco.exec</jacoco-agent.destfile> -->
<jacoco-agent.destfile>${sonar.jacoco.itReportPath}</jacoco-agent.destfile>
</systemPropertyVariables>
<includes>
<include>**/*ITest.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- MAVEN Jacoco plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>**/*UTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>