Skip to content

Instantly share code, notes, and snippets.

@eramax
Created September 26, 2021 16:40
Show Gist options
  • Save eramax/5db90ff4c618de57927e1a9457e3348c to your computer and use it in GitHub Desktop.
Save eramax/5db90ff4c618de57927e1a9457e3348c to your computer and use it in GitHub Desktop.
Code coverage of your tests in .NET
using App1;
using Xunit;
/// <summary>
/// How to collect the code coverage of your tests in .NET
/// https://www.youtube.com/watch?v=xwMWGYD8rgk
/// Calculate code coverage by cli command
/// dotnet tool install -g coverlet.console
/// coverlet .\bin\Debug\net5.0\App1.dll --target "dotnet" --targetargs "test --no-build"
/// dotnet test --collect:"XPlat Code Coverage"
/// dotnet tool install -g dotnet-reportgenerator-globaltool
/// reportgenerator -reports:".\TestResults\b6450279-e558-45bc-b8d3-b7575a7f417e\coverage.cobertura.xml" -targetdir:"coverage" -reporttype:Html
/// </summary>
namespace TestProject1
{
public class UnitTest1
{
[Fact]
public void SumTest()
{
Assert.Equal(Program.Sum(10 , 5), 15);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment