Error observed: the pipeline runs well but the code coverage is not showing, and the following message is shown: There is not enough lines to compute coverage, but actually the PR has more than 100 lines of new code not covered
Hi Colin, thanks for the response, I used the same workflow that the tutorial suggested and the analysis is showing that new code was added and need coverage, (so the message: There is not enough lines to compute coverage disappeared) now I added some tests for that new code, but it seems the analysis is not considering those unit tests, is it necessary to add another configuration to the workflow?
public CoverageTestServiceTests()
{
_service = new CoverageTestService();
}
[Fact]
public void Add_WithValidInputs_ReturnsSum()
{
// Arrange
var a = 5;
var b = 3;
// Act
var result = _service.Add(a, b);
// Assert
Assert.Equal(8, result);
}
[Fact]
public void Subtract_WithValidInputs_ReturnsDifference()
{
// Arrange
var a = 10;
var b = 4;
// Act
var result = _service.Subtract(a, b);
// Assert
Assert.Equal(6, result);
}
[Fact]
public void Multiply_WithValidInputs_ReturnsProduct()
{
// Arrange
var a = 6;
var b = 7;
// Act
var result = _service.Multiply(a, b);
// Assert
Assert.Equal(42, result);
}
[Fact]
public void Divide_WithValidInputs_ReturnsQuotient()
{
// Arrange
var a = 10;
var b = 2;
// Act
var result = _service.Divide(a, b);
// Assert
Assert.Equal(5.0, result);
}
[Fact]
public void Divide_ByZero_ThrowsDivideByZeroException()
{
// Arrange
var a = 10;
var b = 0;
// Act & Assert
var exception = Assert.Throws<DivideByZeroException>(() => _service.Divide(a, b));
Assert.Equal("Cannot divide by zero", exception.Message);
}
[Fact]
public void GetGreeting_WithValidName_ReturnsPersonalizedGreeting()
{
// Arrange
var name = "John";
// Act
var result = _service.GetGreeting(name);
// Assert
Assert.Equal("Hello, John!", result);
}
[Fact]
public void GetGreeting_WithNullName_ReturnsAnonymousGreeting()
{
// Arrange
string? name = null;
// Act
var result = _service.GetGreeting(name);
// Assert
Assert.Equal("Hello, Anonymous!", result);
}
[Fact]
public void GetGreeting_WithEmptyName_ReturnsAnonymousGreeting()
{
// Arrange
var name = "";
// Act
var result = _service.GetGreeting(name);
// Assert
Assert.Equal("Hello, Anonymous!", result);
}
}
Thanks for sharing this documentation I was able to get the coverage, I want to share the final github workflow that worked for me (in case it can help someone else), just added an step (Install dotnet-coverage) for installing dotnet-coverage which is the tool I wanted to use, and updated the last step (Build and analyze) to let know the scanner where the coverage would be located, then running he actual tool to get the coverage.