使用maven进行junit插件测试的代码覆盖率

时间:2015-07-07 06:39:52

标签: java eclipse maven eclipse-plugin jacoco

以下是我的产品单元测试的maste pom文件配置文件。我们有junit插件测试。 这些pom文件配置没有在任何位置给我jacoco代码覆盖文件(.exec)。 请帮助我,如果有任何错误的地方。谢谢

    <profile>
        <id>unit-tests</id>
        <modules>
            <module>../../../test/com.xxxx.tools.comms.test.utilities</module>

            <!-- product related unit tests 
            <module>../../../test/com.xxxx.comms.product.test</module>
            <module>../../../test/com.xxxx.comms.product.mas.test</module>-->
            <module>../../../test/com.xxxx.comms.product.iv.test</module> 
        </modules>

        <properties>
            <!-- Properties to enable jacoco code coverage analysis -->
            <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.2.201409121644</version>
                    <configuration>
                        <!-- Where to put jacoco coverage report -->
                        <destFile>C:/Userdata/product/GIT/Team/coverage/product1/jacoco/12.exec</destFile>
                    </configuration>
                    <executions>
                        <execution>
                            <id>jacoco-initialize</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>

                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>


<build>
        <plugins>
            <!-- Use of Tycho -->
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <includes>
                        <include>**/Tests*.java,**/*Tests.java,**/*TestCase.java,**/Test*.java,**/*Test.java</include>
                    </includes>
                    <argLine>${argLine}</argLine>
                    <useUIHarness>true</useUIHarness>
                    <!-- Kill test JVM if tests take more than 1 minute to finish -->
                    <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>

            </plugin>

            <!-- Configuration of target platforms -->
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <pomDependencies>consider</pomDependencies>
                    <resolver>p2</resolver>
                    <environments>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86</arch>
                        </environment>
                    </environments>
                </configuration>
            </plugin>

        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.tycho</groupId>
                    <artifactId>tycho-packaging-plugin</artifactId>
                    <version>${tycho-version}</version>
                    <configuration>
                        <!-- workaround for TYCHO-349 or TYCHO-313 -->
                        <strictVersions>false</strictVersions>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.eclipse.tycho</groupId>
                    <artifactId>tycho-compiler-plugin</artifactId>
                    <version>${tycho-version}</version>
                    <configuration>
                        <source>${jdk.version}</source>
                        <target>${jdk.version}</target>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>

1 个答案:

答案 0 :(得分:2)

我得到了问题来源 罪魁祸首是 tycho-surefire-plugin 配置中的<argLine>参数。
如果存在此参数,则不会生成jacoco文件。我删除了它,现在生成了.exec文件 更多信息,请访问tycho-surefire argLine causes no jacaco.exec