Coverlet: An error report when generate cobertura report

Created on 6 Aug 2018  路  15Comments  路  Source: coverlet-coverage/coverlet

I want to generate the cobertura format report in .netcore project:
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura My.Test.csproj

And I get the following error:
C:\Users\asus.nuget\packages\coverlet.msbuild\2.1.1\build\netstandard2.0\coverlet.msbuild.targets(23,5): error : Index was outside the bounds of the array.

bug

Most helpful comment

@tonerdo I've got it fixed locally on my machine. I'll clean it up and put in PR when I get off work.

All 15 comments

I ran into the same issue. I did a bit of testing and it seems to only be happening when there is no coverage to report. For example, if on a new project testing an empty class lib, you exclude [NUnit*]*.

I ran into a similar issue, in my case it was auto-gen'd protobuf files. Excluding the offending classes ended up working for me. The hard part is figuring out which part of your code is it throwing on.

This only happens when generating Cobertura reports. All the other modules by happenstance foreach over the modules before doing any real calculations.

I've pinned it down to this line: https://github.com/tonerdo/coverlet/blob/a334be0ac0bb60bd4a157bcac3a077f7a06930ff/src/coverlet.core/Reporters/CoberturaReporter.cs#L34

which segues to the index out of range here:

https://github.com/tonerdo/coverlet/blob/a334be0ac0bb60bd4a157bcac3a077f7a06930ff/src/coverlet.core/Reporters/CoberturaReporter.cs#L147

It happens when the result.Modules array is empty. I was testing an empty unit test project and it threw this error.

I encountered this issue also while setting up a Skeleton solution & CI pipeline in VSTS for a new project.

Looks like it would be a simple fix with a little defensive code checking the length of the array before referencing its contents.

Anyone wanna open a quick PR for that?

@tonerdo I've got it fixed locally on my machine. I'll clean it up and put in PR when I get off work.

Any progress with that issue. I am forced to exclude more and more proj files from coverage generation because of this problem. @InKahootz, is the PR already submitted?

@totollygeek have you tried the latest NuGet package? The offending code is no longer present

Yeap, still the same:
error : Index was outside the bounds of the array.
error : at Coverlet.Core.Reporters.CoberturaReporter.Report(CoverageResult result)

I am guessing the problem is somewhere here:

method.Add(new XAttribute("name", meth.Key.Split(':')[2].Split('(')[0]));
method.Add(new XAttribute("signature", "(" + meth.Key.Split(':')[2].Split('(')[1]));

It happens when last assembly in test assemblies has no tests.
Working example:

Module                   Line   Branch   Method
Tests.Project.Api        0%     0%       0%
Tests.Project.Domain     n%     n%       n%

Not working example:

Module                   Line   Branch   Method
Tests.Project.Domain     n%     n%       n%
Tests.Project.Xtra       0%     0%       0%

The question is why should I test assemblies without tests.
The workaround it to create test with Assert.IsTrue(true) for empty project.

@totollygeek @LosDavidos can you provide a repro?I cannot repro on my local.

Getting the same error with cobertura but works with opencover

Total tests: 14. Passed: 14. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.9901 Seconds
Calculating coverage result... Generating report './coverage.xml' /home/pnahar/.nuget/packages/coverlet.msbuild/2.6.1/build/coverlet.msbuild.targets(37,5): error : Index was outside the bounds of the array. [/home/pnahar/dev-zone/ccc-repos/sdk/Platform/Platform-Api/zzz.Test/zzz.Test.csproj] /home/pnahar/.nuget/packages/coverlet.msbuild/2.6.1/build/coverlet.msbuild.targets(37,5): error : at Coverlet.Core.Reporters.CoberturaReporter.Report(CoverageResult result) in C:\Users\toni\Workspace\coverlet\src\coverlet.core\Reporters\CoberturaReporter.cs:line 21 [/home/pnahar/dev-zone/ccc-repos/sdk/Platform/Platform-Api/zzz/zzz.csproj] /home/pnahar/.nuget/packages/coverlet.msbuild/2.6.1/build/coverlet.msbuild.targets(37,5): error : at Coverlet.MSbuild.Tasks.CoverageResultTask.Execute() in C:\Users\toni\Workspace\coverlet\src\coverlet.msbuild.tasks\CoverageResultTask.cs:line 106 [/home/pnahar/dev-zone/ccc-repos/sdk/Platform/Platform-Api/zzz.Test/zzz.Test.csproj]

I ran into a similar issue, in my case it was auto-gen'd protobuf files. Excluding the offending classes ended up working for me. The hard part is figuring out which part of your code is it throwing on.

@xtiancapil I believe I'm running into this with my auto-gen protobuf files as well. How do you exclude them?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arohithr8 picture arohithr8  路  5Comments

arpit-nagar picture arpit-nagar  路  4Comments

civspan picture civspan  路  6Comments

escalonn picture escalonn  路  6Comments

spboyer picture spboyer  路  3Comments