Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scoverage how to exclude files and packages?

Tags:

scoverage

I am trying to exclude packages and files from the scoverage report.

However it does not exclude the specified files and packaged.

I am doing this:

<excludedPackages>*api.test.*</excludedPackages> 
<excludedFiles>.*File.scala</excludedFiles>

Could someone suggest how it works for you ?

Cheers V.

like image 237
axy3yz Avatar asked Dec 22 '17 10:12

axy3yz


2 Answers

Similar to https://stackoverflow.com/a/44346781/2370679

Add the following to your build.sbt file:

To exclude packages (e.g. to exclude *api.test.* and *api.db* packages):

coverageExcludedPackages := "<empty>;*api.test.*;*api.db*"

You can also use the syntax to exclude files:

coverageExcludedPackages := "*File.scala"

For your specific example, you can try:

coverageExcludedPackages := "*File.scala;*api.test.*"

Reference: https://github.com/scoverage/sbt-scoverage#exclude-classes-and-packages

like image 182
muya_ Avatar answered Nov 17 '22 17:11

muya_


You seem to be doing this right, though I'm not familiar exactly with the Maven plugin which you seem to be using.

Thing is, when scoverage excludes files, it still compiles the classes in them, but it doesn't instrument them, resulting in a .class file identical to one which will be produced by compilation without the plugin. This might be confusing you to see .class files for classes originated in source files you explicitly excluded -- it sure did confuse me -- but this is how the plugin works.

Update:

The Scoverage scalac plugin will try to match file paths to the regex after removing .scala from them; i.e, omit the .scala from your regex as it will never match any file pattern.

Also note that the regex is matched against paths and not class names; i.e, use / instead of \.. Can't say if this works on Windows (if not then it's a bug with the scalac plugin).

like image 1
Eyal Roth Avatar answered Nov 17 '22 17:11

Eyal Roth