Java Jacoco代理不测量exec maven插件运行的任何代码覆盖率
我想用execmaven插件和jacoco一起测量代码覆盖率 现在,我可以执行我的主类(没有覆盖),并且可以测量我的单元测试覆盖率。我想在运行我的主类时测量代码覆盖率 运行我的主类没问题(clean compile exec:java):Java Jacoco代理不测量exec maven插件运行的任何代码覆盖率,java,maven,exec-maven-plugin,jacoco-maven-plugin,Java,Maven,Exec Maven Plugin,Jacoco Maven Plugin,我想用execmaven插件和jacoco一起测量代码覆盖率 现在,我可以执行我的主类(没有覆盖),并且可以测量我的单元测试覆盖率。我想在运行我的主类时测量代码覆盖率 运行我的主类没问题(clean compile exec:java): <profiles> <profile> <id>scenarioInitiator</id> <build>
<profiles>
<profile>
<id>scenarioInitiator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.mycompany.Main</mainClass>
<arguments>
<argument>123456</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
场景发起者
org.codehaus.mojo
execmaven插件
1.2.1
com.mycompany.Main
123456
我的jacoco单元测试配置正常(清洁测试):
<profiles>
<profile>
<id>scenarioInitiator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.mycompany.Main</mainClass>
<arguments>
<argument>123456</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
org.jacoco
jacocomaven插件
0.7.5.201505241946
真的
单元前测试
配制剂
${project.build.directory}/coverage reports/jacoco-ut.exec
surefireArgLine
单元后测试
测试
报告
${project.build.directory}/coverage reports/jacoco-ut.exec${project.reporting.outputDirectory}/jacoco-ut
但在运行主类时,实际上不会运行测试,因此无法收集测试覆盖率。你到底想实现什么?@A.Di Matteo,我想衡量一下我的主类执行所涵盖的代码抱歉,还不清楚。您想让您的类测量所涵盖的代码吗?我的意思是,类的预期行为应该是运行所有测试并测量测试覆盖率?但当运行主类时,实际上不会运行测试,因此无法收集测试覆盖率。你到底想实现什么?@A.Di Matteo,我想衡量一下我的主类执行所涵盖的代码抱歉,还不清楚。您想让您的类测量所涵盖的代码吗?我的意思是,类的预期行为应该是运行所有测试并测量测试覆盖率?