前提:單元測試和被測代碼在一個倉庫
maven的pom配置
依賴增加
<dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.agent</artifactId> <version>0.8.3</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin --> <dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.3</version> </dependency>
插件增加
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.7</version> <configuration> <skipEmptyReport>false</skipEmptyReport> </configuration> <executions> <execution> <phase>verify</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.3</version> <executions> <execution> <goals> <goal>prepare-agent</goal> <goal>report</goal> </goals> </execution> </executions> </plugin>
jenkins安裝jacoco插件,在job配置中增加構建后步驟:Record JaCoCo coverage report
pom命令輸入
clean install test