对于用Powermock编写的测试用例,sonar中单元测试覆盖率统计不正确的问题

用PowerMock写的单元测试用例,sonar中覆盖率显示问题

  • sonar中没有覆盖率的显示问题
  • sonar中覆盖率显示不正确
  • sonar中单元测试用例个数不正确问题

sonar中没有覆盖率的显示问题

  • pom文件中jacoco-maven-plugin配置不正确,做了如下配置,sonar中有了覆盖率的显示

         <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.9</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-prepare-agent-integration</id>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report-integration</id>
                        <goals>
                            <goal>report-integration</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.0</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

sonar中覆盖率显示不正确

  • sonar中覆盖率的统计为0.0%1

PowerMock的版本从1.6.3改为1.6.6,覆盖率从0.0%变为有正常数据

sonar中统计的单元测试个数不正确

单元测试用例中多了很多名为setUp和tearDown的测试用例,按照正常的来说,这个函数不应包含在测试用例里面,报错如下:

    Error Message
    The class xx.xx.xx.xx.xx not prepared for test. To prepare this class, add class to the '@PrepareForTest' annotation. In case if you don't use this annotation, add the annotation on class or  method level.  

    Stacktrace
    org.powermock.api.mockito.ClassNotPreparedException: 
    The class xx.xx.xx.xx.xx not prepared for test.
    To prepare this class, add class to the '@PrepareForTest' annotation.
    In case if you don't use this annotation, add the annotation on class or  method level. 

最后在@PrepareForTest()中添加了这个类之后,单元测试个数统计正确

    @Test (groups = {"UT"})
    @PrepareForTest({ClassName1.class,ClassName2.class})
    @PowerMockIgnore({""})
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值