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 dropped 20%

See original GitHub issue

Hello,

I’ve been using the report generator for a few months now without any major hiccups until just recently. Something has changed on the branch coverage generation and I can’t make any sense of how to resolve it. My branch coverage has dropped from ~80% to ~60% without nearly that many changes being made to the code.

An example is this: image

The message shows 2/4 branch coverage, but it is on the method opening bracket which makes no sense at all. Can anyone tell me how to address this because this appears to be where I have lost the big percentage.

The tests for the code shown above are as follows:


[Fact]
public async Task Delete_OkRequest_ReturnsJson()
{
	// Arrange
	_mockBlogService.Setup( s => s.Tags.GetByID( It.IsAny<int>() ) )
		.ReturnsAsync( new Tag() );

	_mockBlogService.Setup( s => s.Tags.Delete( It.IsAny<int>() ) )
		.ReturnsAsync( HttpResponseHelper.GetHttpResponse( null, System.Net.HttpStatusCode.OK ) );

	// Act / Assert
	var result = Assert.IsType<JsonResult>( await _controller.Delete( new TagViewModel() ) );
}

[Fact]
public async Task Delete_BadRequest_ReturnsJson()
{
	// Arrange
	_mockBlogService.Setup( s => s.Tags.GetByID( It.IsAny<int>() ) )
		.ReturnsAsync( new Tag() );

	_mockBlogService.Setup( s => s.Tags.Delete( It.IsAny<int>() ) )
		.ReturnsAsync( HttpResponseHelper.GetHttpResponse( null, System.Net.HttpStatusCode.BadRequest ) );

	// Act / Assert
	var result = Assert.IsType<JsonResult>( await _controller.Delete( new TagViewModel() ) );
}

[Fact]
public async Task Delete_ErrorOnAPI_ReturnsJson()
{
	// Arrange
	_mockBlogService.Setup( s => s.Tags.GetByID( It.IsAny<int>() ) )
		.ThrowsAsync( new System.Exception() );

	// Act / Assert
	var result = Assert.IsType<JsonResult>( await _controller.Delete( new TagViewModel() ) );
}

Granted these are not thorough as far as checking the results, but they should still be hitting all branches.

Here are shots of the overall coverage drop: BEFORE image

AFTER image

Thank you for any assistance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lostchopstikcommented, Mar 5, 2020

@MarcoRossignoli sure thing, I’ll see if I can make a simple repro on a new project, otherwise, I’ll try to provide as much detail as I can with what I have now.

0reactions
danielpalmecommented, Mar 10, 2020

I’m closing this issue since ReportGenerator parses the coverage file correctly.
The coverage file itself seems to be incorrect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unit testing - Unexpected Code Coverage Reduction
I am adding unit tests to some existing code which initially was not tested at all. I have set up my CI system...
Read more >
c# - Branch Coverage Issue
I've removed most of the code, and found that the issue is to do with this conditional if (orderLine.Tracking.EndStateDate.GetValueOrDefault() < ...
Read more >
Sudden significant coverage drop - Bug Fixes
The drop appeared few days after our release, we prepared some docs' changes as Pull Requests and they suddenly showed us ~23% coverage...
Read more >
Incorrect Jest coverage · Issue #3854 · swc-project/swc
I've noticed that jest coverage will report code branches inside helper functions as being uncovered lines unless the externalHelpers:true ...
Read more >
Different code coverage types and the importance of a ...
Branch coverage sees the conditional logic branches in the code and ensures that tests cover all of them. To get full branch coverage...
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