Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ - exclude some classes (packages) from test coverage report

I am currently using Java with Play framework. I have JUnit tests and I am trying to measure coverage with IntelliJ coverage runner.

Play unfortunately generates some rubbish classes and IntelliJ includes them in the report. Is there a way of excluding certain patterns from coverage report?

like image 660
Xorty Avatar asked Jan 28 '15 14:01

Xorty


People also ask

How do you exclude a class from code coverage?

Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report.

How do I exclude test classes in IntelliJ?

To exclude let's say "integration-test", you just need to specify as tags: ! integration-test , and IntelliJ will run all your JUnit5 tests except the ones tagged with integration-test . Take a look at this answer for details (including screenshot).

What is code coverage in IntelliJ?

Code coverage. Code coverage in IntelliJ IDEA allows you to see the extent to which your code has been executed. It also lets you verify the extent to which your code is covered by unit tests, so that you can estimate how effective these tests are. Code coverage is supported only for the classes and sources that belong to your current project.

What is the difference between including and excluding packages in IntelliJ?

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.

How do I exclude classes from code coverage report?

Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report. What I want is coding the classes to be excluded i.e in the pom file like I did with exclusion of code for sonar qube. To make it short. How do I do this programmatically?.

Is it possible to exclude certain sections of JS code?

Some branches in JS code are typically hard, if not impossible to test. Examples are a hasOwnProperty check, UMD wrappers and so on. Istanbul now has a facility by which coverage can be excluded for certain sections of code. What’s more, 100% coverage isn’t necessary or even reasonable in most cases.


1 Answers

You can specify which classes will be added to coverage data by editing run configuration of the test (tests) being executed.

Click on "Edit Configurations" when you have selected your test, open Code coverage settings tab and inside "Packages and classes to record coverage data" you can narrow down the packages from production code included in recording of coverage.

like image 56
MichalD Avatar answered Sep 16 '22 14:09

MichalD