I have a maven module containing code but no tests. Tests are in another module.
- code-module
- test-module
I use JaCoCo to report about the code coverage, but it seems that no JaCoCo report is generated in the code-module because there are no tests to run. Without such report, the aggregate report in the test-module does not include the code coverage from the code-module's code.
How do I make sure the jacoco report is generated even when there are no tests?
Where I think the problem lies
I found out that the problem may lie with the way the maven-surefire-plugin handles the case where no tests are found.
The maven logs then show:
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ code-module ---
followed by
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ data-product-model ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Adding a single test class (that may be empty) changes this output to
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ code-module ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit.JUnit3Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.code.CodeCoverageTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in com.example.code.CodeCoverageTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
and suddenly it generates surefire-reports/ and the jacoco.exec and site/jacoco/
(even though there are no actual tests, just an empty CodeCoverageTest.java),
so I see that the jacoco-maven-plugin is able to report:
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ code-module ---
[INFO] Loading execution data file /workspaces/example/code-module/target/jacoco.exec
Question
Instead of adding such a dummy test class, is there a way to configure maven-surefire-plugin to generate the jacoco stuff always?
Maybe something I can put in the parent pom, so it will automatically work for all child-module without tests.