工具

Sonar UT代码覆盖率

Sonar UT代码覆盖率
sonar 覆盖率
答复
17-2-23 上午3:13
# 资料
 
 
 
# 步骤
 
项目无需任何变动,Maven命令变更为以下即可:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true
 
 
# Coverage per test模式
 
这种模式可以详细追踪每个单元测试关联到哪些类。但是试验时不成功。
 
1. 修改 pom.xml
  <!-- BEGIN: Specific to mapping unit tests and covered code -->
  <profiles>
    <profile>
      <id>coverage-per-test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- Minimal supported version is 2.4 -->
            <version>2.13</version>
            <configuration>
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
            </configuration>
          </plugin>
        </plugins>
      </build>
 
      <dependencies>
        <dependency>
          <groupId>org.sonarsource.java</groupId>
          <artifactId>sonar-jacoco-listeners</artifactId>
          <version>3.8</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
  <!-- END: Specific to mapping unit tests and covered code -->
2. Maven命令指定 profile
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true -Pcoverage-per-test
 
然并卵,生成的报告无任何变化。日志报:No information about coverage per test.
 
怀疑是 jacoco-maven-plugin 版本太高,尝试降到 0.7.5 版本,依然无用
mvn clean org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:prepare-agent install -Dmaven.test.failure.ignore=true -Pcoverage-per-test
 
 
 
0 (0 票)