Jacoco代理不会测量exec-maven-plugin运行的任何代码覆盖率

时间:2016-06-21 13:27:07

标签: java maven exec-maven-plugin jacoco-maven-plugin

我想用exec-maven-plugin和jacoco一起测量代码覆盖率。

现在,我可以执行我的Main类(没有封面),我可以测量我的单元测试的覆盖范围。我想在运行我的主类时测量代码覆盖率。

运行我的Main类是OK(clean compile exec:java):

<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>

我的单元测试jacoco配置正常(干净测试):

<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>

0 个答案:

没有答案