Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files from IntelliJ code coverage by name pattern?

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?

enter image description here

like image 946
deamon Avatar asked Dec 18 '17 10:12

deamon


People also ask

How do you exclude a class from code coverage?

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.

How do I configure code coverage in IntelliJ?

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.


Video Answer


1 Answers

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.

like image 77
Robin Avatar answered Oct 25 '22 11:10

Robin