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

2

13

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

Dairen answered 18/12, 2017 at 10:17 Comment(2)
Could you please share some example names of test classes? It's hard to guess what kind of regular expression should be used, if an output is unknown.Brandt
I've added a name as example.Dairen
S
6

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.

Shippy answered 22/1, 2018 at 10:5 Comment(0)
R
0

As of IntelliJ 2021.1.1, it appears very basic regex is accepted. In my own project, the package com.foo.bar.service.* is included in the coverage options. Sadly, this includes all the test classes as well, which I want excluded from the report.

To exclude those test classes, add one of them manually. Since my project has a naming standard for test classes, I can edit the text of the exclusion from com.foo.bar.service.ClassTest to read com.foo.bar.service.*Test. This will exclude all the test classes from the report as well as not include them in coverage calculations.

Ribbentrop answered 4/4, 2023 at 14:19 Comment(1)
I will add that after doing this the one time, it seems impossible to get the test classes for me to show up in the coverage report. I've removed the exclusion pattern and they still won't come backRibbentrop

© 2022 - 2024 — McMap. All rights reserved.