Before doing statistical code test coverage, generally with cobertura. Previously statistical test coverage, generally only unit test, or close the eyes of the unit test and integration test together.
However, we have gone through the age of superstition UT:
- UT does not support large-scale refactoring, and if the refactoring of classes and methods is split, UT loses the function of ensuring that refactoring code is still correct, and it takes time to rewrite the new classes and methods, and other use cases to change the mock of old classes and methods is also a nightmare.
- UT does not support user story-based testing, even if coverage is 100%, and is not guaranteed to be what the product manager wants.
- UT assumptions about the behavior of input parameters and mock objects, there are potential risks
- Multi-threaded, network, etc. difficult to test places.
In my opinion, integration testing using embedded containers, such as spring Boot's set of integrated test systems based on embedded JETTY,H2 and so on, integrates UT (which can be run locally, can be directly assert the application's internal properties, can be statistically coverage, If CI fails and can be independently run locally, debug, repair failed case resubmit) and FT (based on the User story black box test) advantages, the status of the project quality assurance is not lower than UT, so also need to calculate coverage, rather than the traditional test pyramid model, only rely on UT coverage.
So Sonar + Jacoco is a very useful combination of both UT and it test coverage.
Copy Sonar's own MAVEN Ut/it sample project, with Maven plugin, it's easy to run out of effect, slightly.
It took me half a day to run the same effect with Jenkins on the Sonarquberunner, because Sonarquberunner didn't know who Maven was.
On the internet is a semi-new scuffed, not salty articles, and groped for a round, to arrive at a one-off, it is guaranteed to run Jenkins + Maven + Sonar + Jacoco configuration
Use the latest Sonarqube Runner 2.4 on Jenkins and fill in the configuration below
Sonar.projectkey=xxx
Sonar.projectname=xxx
Sonar.projectversion=xxx
Sonar.modules=modulea,moduleb,it Module C
#这里假设moduleA, Moduleb in the root directory, Module C under the two-level directory, need to define additional
#moduleC. Projectbasedir=xxx/modulec
Sonar.sourceencoding=utf-8
Sonar.language=java
Sonar.sources=src/main/java
Sonar.tests=src/test/java
Sonar.binaries=target/classes
#排除一些不想统计的类
#sonar. Exclusions=**/*idl.java
Sonar.java.coverageplugin=jacoco
Sonar.jacoco.itreportpath=xxx/modulec/target/jacoco-it.exec, it's best to write an absolute path
Sonar.junit.reportspath=target/surefire-reports
Sonar.surefire.reportspath=target/surefire-reports
Original address: http://calvin1978.blogcn.com/articles/sonar-jacoco.html
Sonar + Jacoco, powerful UT, IT dual coverage statistics (RPM)