我有一个用于宁静的Web服务Java项目的pom文件,在该项目中,我们使用Jbehave maven插件来运行集成测试并生成测试执行报告。作为新过程的一部分,我不得不在项目中的同一pom文件中实现Jacoco(使用Surefire和Failsafe插件)以生成代码覆盖率报告。现在的问题是,集成测试用例正在运行两次,从而导致Test Db出现问题(一次是Jbehave,另一次是Jacoco FailSafe插件)。有没有一种方法可以修改pom文件,以确保Jacoco FailSafe和Jbehave作为生成各自报告的单个目标运行(即集成测试仅执行一次)
试图注释掉Jacoco故障安全目标或Jbehave,在这种情况下,集成测试仅运行一次,但无法找到一种方法来修改pom文件以确保两个目标都执行,而集成测试用例仅运行一次
可能的话,配置pom文件以确保同时执行Jbehave maven插件和Jacoco故障安全插件目标,但集成测试仅运行一次
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>$(jbehave.core.version)</version>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
<configuration>
<scope>test</scope>
</configuration>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
<configuration>
<includes>
<include>**/Stories.java</include>
</includes>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<!-- The Executions required by unit tests are omitted. -->
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Failsafe plugin is executed.
-->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for integration tests after
integration tests have been run.
-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<!--
Ensures that both integration-test and verify goals of the Failsafe Maven
plugin are executed.
-->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine}</argLine>
<includes>
<include>**/Stories.java</include>
</includes>
<!--
Skips integration tests if the value of skip.integration.tests property
is true
-->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>