-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different output format results in different coverage percentage #1519
Comments
@cremor thanks a lot for reporting this 🙏 . I would also assume the same as you and thus it could really be a bug. Would it be possible for you to provide a simple sample that lets us reproduce this? No obligation at all, it could just help to analyse this faster. |
I don't have access to an IDE for the next few days, but I'll try to drycode a repro 😅 // MyRegexUsage.cs
using System.Text.RegularExpressions;
namespace MyNamespace;
public partial class MyRegexUsage
{
[GeneratedRegex("abc|def")]
private static partial Regex AbcOrDefRegex();
public static bool IsAbcOrDef(string text)
{
return AbcOrDefRegex().IsMatch(text);
}
}
// MyRegexUsageTests.cs
using Xunit;
namespace MyNamespace.Tests;
public class MyRegexUsageTests
{
[Fact]
public void Test()
{
MyRegexUsage.IsAbcOrDef("def");
}
} Run:
After that, you could run both code coverage reports through ReportGenerator to generate a |
Sorry, I can't really reproduce it with your sample. The reports both have the generated functions. Also the coverage summary seems to be the same. Branch coverage 46.66 and line coverage 68.35. <!-- opencover -->
<Summary numSequencePoints="79"
visitedSequencePoints="54"
numBranchPoints="30"
visitedBranchPoints="14"
sequenceCoverage="68.35"
branchCoverage="46.66"
maxCyclomaticComplexity="35"
minCyclomaticComplexity="35"
visitedClasses="6"
numClasses="6"
visitedMethods="9"
numMethods="9" />
Can I ask which version of report generator you were using? Maybe it really is just a display problem. |
Thanks for the analysis. I'll test this again in a few days. |
You are right. It looks like the two xml files contain the same results. But after running them both through ReportGenerator version 5.1.24.0 I get different reports (different line numbers, branch numbers, percentages, ...). What I noticed is that for the Cobertura report ReportGenerator generated two errors with the same message:
But for the OpenCover report it only generated one of those errors:
But even though it shows those two error messages, the converted Cobertura report then shows the This is the command I used for ReportGenerator:
Do you think this is a problem with ReportGenerator and that I should report it there? |
I tried this today with ReportGenerator version 4.8.7.0 and there both files have the same output. With the most current version, 5.1.24.0, the generated reports differ like you described. @danielpalme Can you check if this is an error with our coverage reports or did ReportGenerator's parsers change so that the Cobertura parser now displays generated classes whereas the OpenCover still doesn't. You can find the reports attached to this #1519 (comment). |
I will have a look in september. In general ReportGenerator does not care about whether classes are generated or not. |
@danielpalme You can find the Cobertura (and OpenCover) file here: #1519 (comment) |
I just released version 5.1.25 of ReportGenerator. |
I would have assumed that the code coverage output format ist just that - a file format. But it seems like using a different output format also affects code coverage percentage. Is this by design?
Example:
I use a .NET regular expression source generator in my code.
When I use
dotnet test
with the argument--collect:"XPlat Code Coverage;Format=cobertura"
then it does count the generated code in the namespaceSystem.Text.RegularExpressions.Generated
.When I use
dotnet test
with the argument--collect:"XPlat Code Coverage;Format=opencover"
then it does not count the generated code.Package: coverlet.collector 6.0.0
.NET 7
The text was updated successfully, but these errors were encountered: