Closed
Description
Hi,
In the following code the throw
statement is marked as partially covered (because of the async statemachine), even though I see no way to cover that hidden branch. Could this be detected and marked as covered by coverlet?
public class AsyncThrowReproduction
{
public async Task Execute(bool throwException)
{
try
{
if (throwException)
{
throw new InvalidOperationException();
}
}
catch (InvalidOperationException)
{
await Task.Delay(1);
throw;
}
}
}
Unit Tests:
public class AsyncThrowReproductionFixture
{
[Fact]
public async Task Execute_ShouldWork_Exception()
{
// Arrange
var sut = new AsyncThrowReproduction();
// Act
async Task TestFunc() => await sut.Execute(true);
// Assert
await Assert.ThrowsAsync<InvalidOperationException>(TestFunc);
}
[Fact]
public async Task Execute_ShouldWork_NoException()
{
// Arrange
var sut = new AsyncThrowReproduction();
// Act
await sut.Execute(false);
}
}
Coverlet Version: 3.0.3