Branch coverage with async calls
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:7
- Comments:23
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
I’m seeing this issue still in version 2.5.1 (that’s the version number in Nuget).