I'm using IntelliJ 2017.3 to measure the code coverage of my tests. The code base contains some more or less dumb classes that should be excluded from this measurement. I want to exclude all classes which contain Factory
as part of their name (example: AverageOperatorFactoy
) and tried it with the patterns *Factory
and .*Factory
(although it seems like regex are not used here), but IntelliJ still shows factories in the coverage report.
How can I exclude classes with a name pattern?
The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class or some of its members are not planned to be covered with tests. EditFormModel class shown above can be left out from code coverage by simply adding the attribute.
Configure coverage Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Coverage. Define how the collected coverage data will be processed: Show options before applying coverage to the editor: show the Code Coverage dialog every time you run a new run configuration with code coverage.
I have the same issue using a very basic pattern like
com.example.myproject.somecode.*
While including works as expected, excluding has no effect at all.
This is seems to be a known issue in IntelliJ. See Code coverage Report includes excluded packages
If you don't have too many packages in your project, you could still do the opposite and include only those packages you want using several active include patterns together.
Alternatively you can use the now free IntelliJ plugin Open Clover which offers much better coverage configuration and result browsing than IntelliJ ships with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With