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.

Branch coverage with async calls

See original GitHub issue

I have a project using EF Core with async methods that shows a branch at each await call. One of the branches always shows as uncovered. I’ve created a sample repo that repoduces the problem here. You can see the branch in the coverage report but the referenced line does not have a branch.

Here is the output of dotnet test:

$ dotnet test /p:CollectCoverage=true
Build started, please wait...
Build completed.

Test run for /Users/clucas/Source/clucas/coverlet-test/Test/bin/Debug/netcoreapp2.1/Test.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.0845 Seconds

Calculating coverage result...
  Generating report '/Users/clucas/Source/clucas/coverlet-test/Test/coverage.json'

+---------+--------+--------+--------+
| Module  | Line   | Branch | Method |
+---------+--------+--------+--------+
| Example | 90.9%  | 50%    | 80%    |
+---------+--------+--------+--------+

I tired another example with await HttpClient.GetAsync(...) but that did not seem to produce the same issue so this doesn’t appear to apply to all awaited calls.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:23

github_iconTop GitHub Comments

4reactions
tonerdocommented, Jun 28, 2018

Thanks for reporting this guys. I’m currently working on general improvements to the coverage logic so will add this to the list. Thanks for the test project @abe545

3reactions
sugarjigcommented, Jan 25, 2019

I’m seeing this issue still in version 2.5.1 (that’s the version number in Nuget).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Branch coverage Issue - async await #1177
Hi again) Code: namespace CoverletAsync { public class MyService { public async Task GetBytes(Func > process, Func > getStream, ...
Read more >
visual studio 2012 - Code coverage for async methods
When I analyse code coverage in Visual Studio 2012, any of the await lines in async methods are showing as not covered even...
Read more >
Code Coverage with Async Await - Presentation Source
The reason the code is not shown as being covered has to do with how async methods are implemented. The C# compiler actually...
Read more >
C# async methods are not highlighted (red/green) in code ...
Hello,. I'm using SonarCloud and I have c# source code using Task and async methods. There is 2 ways I can write the...
Read more >
Code Coverage Criteria for Asynchronous Programs
Statement coverage measures the number of lines of code execrised by the tests, while branch coverage measures the num- ber of branches (e.g.,...
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