定向班第一期_sonar 覆盖率应用

参考资料

字节码插桩技术

  • java agent
  • asm
  • javaassit

验收阶段的覆盖率分析

java \\
-javaagent:/Users/seveniruby/Downloads/org.jacoco.agent-0.8.4-runtime.jar \\
-jar bin/ApacheJMeter.jar

java \\
-jar /Users/seveniruby/Downloads/org.jacoco.cli-0.8.4-nodeps.jar \\
report jacoco.exec \\
--classfiles bin/ApacheJMeter.jar \\
--html jacoco/html \\
--csv jacoco/jacoco.csv \\
--xml jacoco/jacoco.xml

单元测试覆盖率统计

pom修改

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.3</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>COMPLEXITY</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.60</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>@{argLine}</argLine>
                </configuration>
            </plugin>
mvn clean test jacoco:report

sonar集成覆盖率

默认会找target/jacoco.exec

精准化测试平台

下节课测试平台里讲解

练习1

  • 统计JMeter的覆盖率

作业2

  • 把两个作业都实现,并上传到演练环境,并把截图回复到帖子下
  • 也可以自己去找项目测试覆盖率
关闭