Multiple Web services are started in Docker, and there are dependencies between the services. The startup port number and the dependent mirror relationship are configured in the docker-compse.yml file. You need to use code coverage tools to perform coverage statistics on back-end Java code.

1. Jacoco+ Docker + Ant environment construction

The ideal goal of environment construction is that after the coverage statistics tool is enabled, the coverage can be counted by API, Web GUI, manual test and unit test, and an intuitive report can be generated. The progress of code coverage can be viewed at any time, and the coverage of each line of code can be clearly analyzed.

After investigating various code coverage tools, Jacoco was finally selected for code coverage statistics for the following reasons:

1.Jacoco functionality meets the ultimate goal of the code coverage environment described above;

2. Can be integrated with Jenkins;

3. The new Jacoco also supports Kotlin’s code statistics;

4. The tool is being continuously updated.

1.1 Jacoco environment construction blood and tears history

Compared to other coverage tools, the Jacoco environment is more complex to build and relies on source code. Jacoco tools for network query are mostly combined with Tomcat, and JavaAgent is started in Tomcat. Therefore, jacoco + Tomcat is also the first choice, and the flow is found to be passable, but the coverage is always 0. Since then, the following three solutions have been tried.

Code Coverage tool – Jacoco Environment Setup