对于用Powermock编写的测试用例,sonar中单元测试覆盖率统计不正确的问题
2017-03-31 23:25
489 查看
用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%1PowerMock的版本从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({""})参考资料:https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo. ↩
相关文章推荐
- Powermock and sonar jacoco的覆盖率不兼容问题解决 1
- Powermock and sonar jacoco的覆盖率不兼容问题解决 3
- Powermock and sonar jacoco的覆盖率不兼容问题解决 2
- 编写软件测试用例应注意的问题
- 测试用例评审发现问题统计
- [单元测试]PowerMock+SpringMVC整合并测试Controller层方法(一)
- sonar + jacoco + mockMvc 模拟session 用户登录 配合SpringSecurity 权限 快速测试代码覆盖率.
- 单元测试不是梦,Android+PowerMock系列(1) —— 在Eclipse里搭建测试环境
- [单元测试]PowerMock+SpringMVC整合并测试Controller层方法(二)
- 使用Powermock进行单元测试,以及常见问题的处理
- 以下题目均在bookstore项目上完成(请先运行数据库文件): 1、编写单元测试用例,对用户注册功能的Action层进行测试。(注意:测试用例应考虑成功和失败的情况)
- VS2010编写动态链接库DLL及单元测试用例,调用DLL测试正确性
- 【用例】测试用例编写的一些问题
- 测试驱动javascript开发 -- 2.单元测试一例:学习断言、测试用例函数的编写
- VS2010编写动态链接库DLL及单元测试用例,调用DLL测试正确性
- (1)把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”; (2)编写单元测试进行测试; (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。
- (1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”); (2)编写单元测试进行测试; (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。
- jacoco + junit + mock 单测没有统计覆盖率问题
- 单元测试的测试用例编写方法
- VS2010编写动态链接库DLL及单元测试用例,调用DLL测试正确性