question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage returning %NaN% for .Net Core 3 project with integrated xUnit tests

See original GitHub issue

I’ve created about the simplest test case I can that demonstrates the issue. The test is in the same project as the code being tested, also I’m using git bash, but that should be immaterial.

https://github.com/tracker1/bug-dotnet-test-coverage

run-tests.sh

rm -rf bin obj coverage TestResults

dotnet clean

dotnet test \
  -p:Include="[test_coverage.]" \
  -p:Exclude="[*.Test.*]*" \
  -p:CollectCoverage=true \
  -p:CoverletOutputFormat=cobertura \
  -p:CoverletOutput=./coverage/coverage.cobertura.xml

The output I see is as follows…

test-coverage on  master via •NET v3.0.100 took 4s
❯ ./run-tests.sh
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 12/2/2019 3:05:04 PM.
     1>Project "C:\Users\mryan\src\...\test-coverage\test-coverage.csproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Creating directory "obj\Debug\netcoreapp3.0\".
     1>Done Building Project "C:\Users\mryan\src\...\test-coverage\test-coverage.csproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.38
Test run for C:\Users\mryan\src\...\test-coverage\bin\Debug\netcoreapp3.0\test-coverage.dll(.NETCoreApp,Version=v3.0)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.


Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1.2258 Seconds

Calculating coverage result...
  Generating report '.\coverage\coverage.cobertura.xml'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | NaN% | NaN%   | NaN%   |
+---------+------+--------+--------+

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tracker1commented, Dec 3, 2019

@MarcoRossignoli Thanks… this pushed me over the hump in getting side-by-side tests working with coverage.

https://medium.com/@tracker1/add-unit-tests-with-code-coverage-to-your-net-core-project-2367f593246c

0reactions
MarcoRossignolicommented, Dec 3, 2019

Glad to hear! Feel free to close this issue if solved!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverage returning %NaN% for .Net Core 3 project with ...
I've created about the simplest test case I can that demonstrates the issue. The test is in the same project as the code...
Read more >
Coverage returning %NaN% when running unit tests in ...
I have a dot net core version: '3.0.100', building on 'ubuntu-latest' and am trying to get code coverage reports.
Read more >
Use code coverage for unit testing - .NET
Integrate with .NET test. The xUnit test project template already integrates with coverlet.collector by default. From the command prompt, change ...
Read more >
Integration tests in ASP.NET Core
Learn how integration tests ensure that an app's components function correctly at the infrastructure level, including the database, ...
Read more >
How to collect the code coverage of your tests in .NET
NET application both in a quick and easy way but also in a more details view. Code coverage sometimes is a requirement for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found