Jacoco、Maven 和 TestNG(0 测试覆盖率)

mr_*_*owl 5 java testng maven jacoco

我目前正在尝试使用 Maven 和 TestNG 运行 Jacoco。

我还没有下载/安装任何东西。

我尝试将以下内容添加到我的父 POM(也尝试添加到测试包 POM,但仍然没有结果)

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.6.3.201306030806</version>
            <configuration>
                <destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
                <datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
            </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>
Run Code Online (Sandbox Code Playgroud)

当我执行“mvn clean install”或 mvn package 时,输出将作为“test-output”出现在根文件夹中。我尝试在 Maven 中设置“outputDirectory”,但这没有任何作用。

我遇到的另一个更大的问题是它没有进行任何 testNG 测试。代码覆盖率为0。

有人可以帮忙吗?

Kev*_*ave 0

  1. 为什么不将 testNG 依赖项添加到您的 pom 中?
  2. 你们有名字结尾的课程吗<MyClass>Test
  3. 您需要注释该类的方法之一@Test(对您来说很明显)。但请确保指定public访问器。