用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({""})