currently when I run tests in my spring boot app, process test coverage reports are generated for all tests, even those that are not meant to test camunda processes. I know there’s ExcludeFromProcessCoverage annotation, but since there are a lot of test classes, I would prefer to annotate only the ones for which I want to generate coverage reports, using something like IncludeInProcessCoverage. Or is there a way to configure camunda-process-test-coverage-spring-test-platform-7 to include only certain test classes?
Hi @azorahai23 and welcome to the forum.
What integration of the test engine are you using?
Junit5 or Spring testing?
Normally if you only register the extension (Junit5) or import the configuration (spring) for the tests you want coverage for, all other tests shouldn’t be included.
If that’s happening, please open an issue and provide a test case.
Hi @rohwerj
To add a little of context, I have an abstract test class with annotation @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) and @EmbeddedKafka. This class provides common methods and objects such as Camunda ProcessEngine, which I am using to test bpmn process.
I’ve tried to generate reports with both camunda-process-test-coverage-spring-test-platform-7 and camunda-process-test-coverage-starter-platform-7, each had its own issues however.
camunda-process-test-coverage-spring-test-platform-7
With this dependency, I am able to generate report with annotation @Import({CoverageTestConfiguration.class,ProcessEngineCoverageConfiguration.class}) as shown in provided examples. This works fine when I run the test class alone. However, when I am running all of the tests in test/java package, those that are extending the abstract class fails unless they are annotated with @ExcludeFromProcessCoverage, the exception is:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.camunda.community.process_test_coverage.spring_test.platform7.ProcessEngineCoverageProperties’ available
According to the docs, I need to explicitly configure camunda-process-test-coverage-spring-test-platform-7 to include the classes I want in the report, however it doesn’t mention I also need to exclude other test classes with @ExcludeFromProcessCoverage.
camunda-process-test-coverage-starter-platform-7
With this dependency, I am able to generate reports only for classes I want by excluding every other classes with @ExcludeFromProcessCoverage, however, this is not ideal for my case, since I have quite a lot of test classes not meant to test bpmn process. It is the only working solution I’ve been able to find so far though.
For the spring boot starter the behavior is as expected, because the whole setup is autoconfigured for all tests.
For the spring-test approach, it should normally work if you don’t add the test listener to some classes.
Regarding the annotation to include some tests, this would need to be configurable, as I don’t want to break the existing behavior (and even supporting include and exclude at the same time wouldn’t work).
I’m also thinking about some other possibilities.
Maybe it would also work, if we make it possible to annotate the ExcludeFromProcessCoverage on a package level. Would that help you?
Also we could make an include pattern configurable (something like *ProcessTest).
thanks for getting back to me. I think the last approach you mentioned would be the most flexible and coincidentally, currently we are already following that naming convention for classes testing camunda processes.