I have a Java project in VS Code, and I am using Maven as my framework. I have JaCoCo set up to run code coverage reports for my unit tests. I run it using this command:
mvn jacoco:prepare-agent test install jacoco:report -X
However when there is at least one failed test, the code coverage report will not run:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.2:test (default-test) on project <REDACTED> There are test failures.
[ERROR]
[ERROR] Please refer to <REDACTED>/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
I've seen similar questions to this elsewhere, but most of them are for
Android/Gradle
or say to use -Djacoco.haltOnFailure=false
I tried the following command but this doesn't work either.
mvn jacoco:prepare-agent test install -Djacoco.haltOnFailure=false jacoco:report -X
How do I get JaCoCo to create the coverage report, ignoring failed tests?
Hi you can achieve this by adding -Dmaven.test.failure.ignore=true
so your bash command will looks something like this -
mvn jacoco:prepare-agent test -Dmaven.test.failure.ignore=true install jacoco:report -X
By setting -Dmaven.test.failure.ignore=true
Maven will continue with the subsequent goals even if there is a failure during test.
I hope so it helps.