0

我正在尝试为代码覆盖率配置 Jacoco 代理,但它没有产生任何覆盖率。这是我目前的配置:

我有 2 个项目,我们称它们为项目 A 和项目 B。项目 A 是我要为其生成覆盖率报告的地方。它在 wildfly 上运行,我将 Jacoco Agent 配置为 vm 参数,如下所示:

-javaagent:/jacocoagent.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver

项目 B 是一个 maven 项目,我在其中执行测试用例。我配置了 jacoco maven 插件,如下所示:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>generate-report</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <skip>${skip.int.tests.report}</skip>
              <target>
                <!-- Execute an ant task within maven -->
                <echo message="Generating JaCoCo Reports"/>
                <taskdef name="report" classname="org.jacoco.ant.ReportTask">
                  <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar"/>
                </taskdef>
                <mkdir dir="${basedir}/target/coverage-report"/>
                <report>
                  <executiondata>
                    <fileset dir="${basedir}">
                      <include name="target/jacoco-it*.exec"/>
                    </fileset>
                  </executiondata>
                  <structure name="jacoco-multi Coverage Project">
                    <group name="jacoco-multi">
                      <classfiles>
                        <fileset dir="target/classes"/>
                      </classfiles>
                      <sourcefiles encoding="UTF-8">
                        <fileset dir="src"/>
                      </sourcefiles>
                    </group>
                  </structure>
                  <html destdir="${basedir}/target/coverage-report/html"/>
                  <xml destfile="${basedir}/target/coverage-report/coverage-report.xml"/>
                  <csv destfile="${basedir}/target/coverage-report/coverage-report.csv"/>
                </report>
              </target>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.ant</artifactId>
            <version>0.8.4</version>
          </dependency>
        </dependencies>
      </plugin>

我像这样配置了maven surefire插件:

      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
           <!--    Suite testng xml file to consider for test execution -->
                <environmentVariables>
                <BLUEOPTIMA_HOME>${project.basedir}/</BLUEOPTIMA_HOME>
                </environmentVariables>
                <systemPropertyVariables>
                    <BLUEOPTIMA_HOME>${project.basedir}</BLUEOPTIMA_HOME>
                </systemPropertyVariables>
                <suiteXmlFiles>
                    <suiteXmlFile>${project.basedir}/testng.xml</suiteXmlFile>
                    <!--<suiteXmlFile>suites-test-testng.xml</suiteXmlFile> -->
                </suiteXmlFiles>
            </configuration>
        </plugin>

当我执行 mvn test 命令时,它不会生成任何代码覆盖率报告。知道我在这里做错了什么吗?

4

1 回答 1

0

当我执行 mvn test 命令时

在您的配置目标runmaven-antrun-plugin绑定到post-integration-test阶段,这是test阶段之后,因此不由命令执行mvn test- 请参阅https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

于 2019-09-06T17:15:18.147 回答