Reputation: 7271
I use Spring JavaConfig to define my Spring configuration. Since unit tests use a different Spring configuration than production code, the production configuration shows up as 100% uncovered when I use Clover code coverage with unit tests.
I can use the @Configuration
annotation to identify all these classes. Alternatively, I can use the @Bean
annotation to identify all the methods within these classes.
Is there a Clover exclude
or a code context filter that I can set up to globally exclude code by using these annotations? I use the maven-clover2-plugin
to run Clover.
Upvotes: 2
Views: 1296
Reputation: 748
At the moment Clover allows to exclude code from coverage measurement using five methods:
excluding entire file
excluding certain methods
excluding certain statements
excluding certain code blocks
excluding arbitrary source lines
You can put //CLOVER:OFF and //CLOVER:ON inline comments in the source code
Unfortunately, at the moment it's not possible to exclude the given class. However, I can see few workarounds available:
Add the //CLOVER:OFF and //CLOVER:ON comments around classes you want to exclude.
Exclude entire files
Treat these @Configuration classes as test code.
This is a hack. Clover allows to declare which classes are test classes. The match is based on file name, class signature and test signature. See the <clover-setup> / <testsources> / <testclass> tag. In this testclass tag you can define a regular expression matching entire class signature. In your case it could be:
<testclass annotation=".*@Configuration.*"/>
While this will not disable code instrumentation for these classes, they would be treated as test code and they should not contribute to application code metrics.
Note that Clover calculates code metrics for application and test code separately.
References:
Upvotes: 2