|
1 | 1 | Unit tests coverage |
2 | 2 | =================== |
3 | 3 |
|
4 | | -This document explains how to measure your server-side (Java) unit tests coverage using the JaCoCo tool. |
5 | | - |
6 | | -Enable the JaCoCo agent for a specified module <span id="agent"></span> |
7 | | ------------------------------------------------------------------------- |
8 | | - |
9 | | -### Using Docker images |
10 | | - |
11 | | -Our standard images already contains the up-to-date JaCoCo tool by default in the `/usr/local/jacoco` folder. |
12 | | - |
13 | | -To enable coverage measurement of unit tests execution just pass the `JACOCO_MODULES` environment variable to the container with a space-separated list of modules (e.g. `-e JACOCO_MODULES="MyModule MyOtherModule"`). |
14 | | - |
15 | | -The JaCoCo agent exec file is generated at the location denoted by the `JACOCO_DESTFILE` environment variable which defaults to `/usr/local/tomcat/webapps/ROOT/WEB-INF/dbdoc/content/jacoco/jacoco.exec`. |
16 | | -You must ensure persistence for the above `jacoco` folder (which is the case if you already ensure the persistence of the `dbdoc` folder), for instance by mounting a dedicated volume. |
17 | | -This is also useful for report generation as this default folder is also the default location for report files, see bellow. |
18 | | - |
19 | | -To be able to generate a human-readable report (see bellow) you must also mount the `src` and `bin` folders |
20 | | -located in the `/usr/local/tomcat/webapps/ROOT/WEB-INF` folder because both of them are used by the report generation process. |
21 | | - |
22 | | -By default, the exec file is appended when restarting the container, but you can change this by setting the `JACOCO_DESTFILE_APPEND` environment viariable to `false` |
23 | | -(e.g. `-e JACOCO_DESTFILE_APPEND="false"`), in this case the exec file is reset each time the container is restarted. |
24 | | - |
25 | | -> **Note**: you can use the import specification mechanism to automate the modules import and unit tests execution. |
26 | | -
|
27 | | -### Manually |
28 | | - |
29 | | -You can do the same manually for "traditional" Tomcat deployments. |
30 | | - |
31 | | -Download the [JaCoCo tool](https://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.12/jacoco-0.8.12.zip) and unzip it somewhere acessible to Tomcat (noted `<path>` bellow). |
32 | | - |
33 | | -Add following option to JVM arguments when starting Tomcat (in the example bellow only one module is monitored noted `<module>`): |
34 | | - |
35 | | -``` |
36 | | --javaagent:<path>/jacoco-0.8.12/lib/jacocoagent.jar=destfile=<path>/jacoco.exec,includes=com.simplicite.*.<module>.* |
37 | | -``` |
38 | | - |
39 | | -Generate a human-readable report <span id="report"></span> |
40 | | ----------------------------------------------------------- |
41 | | - |
42 | | -Note that **in all cases** (Docker ou manual) the above agent's `jacococ.exec` exec file is generated only **when the JVM is shut down**. |
43 | | - |
44 | | -This means you **must** stop the JVM **before** generating the report as explained bellow. |
45 | | - |
46 | | -### Using Docker images |
47 | | - |
48 | | -You just have to stop and restart the container for the human-readable HTML report to be generated in the folder location denoted by the `JACOCO_REPORTDIR` environment variable which defaults to `/usr/local/tomcat/webapps/ROOT/WEB-INF/dbdoc/content/jacoco` (in order to be available as the static webapp `https://<base url>/content/jacoco/`). |
49 | | - |
50 | | -> **Note**: as said above you should you can make the report folder available outside of the container ensuring its persistence by the appropriate volume. |
51 | | -
|
52 | | -### Manually |
53 | | - |
54 | | -You can manually generate a human-readable HTML report from the JaCoCo agent exec file using the following command: |
55 | | - |
56 | | -```text |
57 | | -java -jar <path>/jacoco-0.8.12/lib/jacococli.jar \ |
58 | | - report <path>/jacoco.exec \ |
59 | | - --html <path>/jacoco \ |
60 | | - --sourcefiles <tomcat root>/webapps/ROOT/WEB-INF/src \ |
61 | | - --classfiles <tomcat root>/webapps/ROOT/WEB-INF/bin |
62 | | -``` |
| 4 | +Moved to [the new documentation](https://documentation.simplicite.io/documentation/devops/tests-coverage) |
0 commit comments