0

I'm not getting any results from opencover. My nunit tests all run and pass, just no coverage results. the problem seems to be opencover filters, but we aren't setting any. Any suggestions?

The CodeCoverage.xml file contains a group of lines like the following which indicate that the plugin is telling opencover to filter out the DLLs we are trying to measure.

<Module hash="A3-F0-3A-1A-FF-38-D7-EF-A2-55-C9-8B-84-37-CF-CF-00-80-70-23" skippedDueTo="Filter">
<FullName>C:\gitlab-runner\builds\83ebc972\0\active\scrpt\output\Scrpt.Core.dll</FullName>
<ModuleName>Scrpt.Core</ModuleName>
<Classes/></Module>

which has the correct path for the dll file, but I don't see why it is skipped due to filtering. The unit tests are contained in a dll called Scrpt.Test.dll and the rest of the code is in other DLLs all of which are being filtered out.

I'm using the following plugins

plugins {
  id 'com.ullink.msbuild' version '2.15'
  id 'com.ullink.nunit' version '1.8'
  id 'com.ullink.opencover-nunit' version '1.6'
}

and the plugin definitions for nunit and opencover are:

nunit {
  testAssemblies = [file('output/Scrpt.Tests.dll')]
  shadowCopy = false
  useX86 = true
  ignoreFailures = false
}

opencover {
  targetAssemblies = [file('output/Scrpt.dll'),file('output/Scrpt.Core.dll'),file('output/Scrpt.SourceCitations.dll'),file('output/ScrptUtilLib.dll')]
  ignoreFailures = false
}

Thank you for your help, -herb

Herb F
  • 135
  • 8

2 Answers2

1

You need to set an opencover filter. Open cover filter works off of inclusive and exclusive filters.

The first filter should always be something like :

+[*]*

meaning include every assembly and every class. then add in your exclusive filters: +[*]* -[AssemblyName]* -[*AnotherName]*

It's very simple. just add in the universal inclusive filter first, get your results, then start to incrementally exclude stuff in your filter one by one.

David Hunsicker
  • 1,140
  • 3
  • 14
  • 24
0

This was answered thru the help of Francois Valdy over at https://github.com/Ullink/gradle-opencover-plugin/issues/17

The problem turned out to be that the opencover plugin was not generating the coverage.xml results. There was an error message in the xml saying that the files I was interested in were skipped because of filters, but I couldn't find what filters were causing that.

I ended up replacing the opencover plugin with a task that does the same thing. Not sure why the plugin didn't work, but the replacement is essentially the same thing in that it calls nunit, creates the output coverage xml which sonarqube then uploads. Plus doing it this way gives you more control over where the files end up.

A bit awkward, but it work. The following replaced the opencover block in my original question.

task opencover(type:Exec) {
 executable 'C:\\Program Files (x86)\\OpenCover\\OpenCover.Console.exe'
 workingDir file('output')
 args "-target:c:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console-x86.exe", "-targetargs:c:\\gitlab-runner\\builds\\83ebc972\\0\\active\\scrpt\\output\\scrpt.tests.dll /noshadow", '-output:coverage.xml', '-filter:+[*]*'
}

btw, I did try replacing the file() uses in the targetAssemblies for the opencover gradle plugin, but that had no effect. From what I've read, the following should've worked.

opencover {
  targetAssemblies = ['output/Scrpt.dll','output/Scrpt.Core.dll','output/Scrpt.SourceCitations.dll','output/ScrptUtilLib.dll']
  ignoreFailures = false
}
Herb F
  • 135
  • 8