You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flowchart LR
A[dotnet test] --> B[Coverlet]
B --> C[coverage.cobertura.xml]
C --> D[ReportGenerator]
D --> E[Dashboard HTML]
style A fill:#74b9ff
style B fill:#fdcb6e
style C fill:#dfe6e9
style D fill:#00b894
Loading
20.2. Generar Informe de Cobertura
Instalar Herramientas
# Coverlet (ya incluido en NUnit)
dotnet add package Coverlet.MSBuild
# ReportGenerator
dotnet tool install -g dotnet-reportgenerator-globaltool
Ejecutar Tests con Cobertura
# Con cobertura
dotnet test --collect:"XPlat Code Coverage"# Con cobertura y threshold
dotnet test --collect:"XPlat Code Coverage" \
/p:Threshold=80 \
/p:ThresholdMode=Exclusive
🟢 publicdecimalCalculateTotal()// Probado{varsubtotal=_items.Sum(i =>i.Price);// 🟢 Probadovardiscount=subtotal>100?10:0;// 🟡 Falta elsereturnsubtotal-discount;}
🔴 publicdecimalCalculateTax()// ❌ Sin tests{return0.21m;// ❌ No ejecutado}
Ejemplo de Código Marcado
🟢 [Test]
🟢 publicvoidCalculateDiscount_WithHighValue_ReturnsDiscount(){// Arrangevarcalculator=newDiscountCalculator();// Actvardiscount=calculator.CalculateDiscount(150m);// AssertAssert.That(discount,Is.EqualTo(10m));}
🔴 [Test]
🔴 publicvoidCalculateDiscount_WithLowValue_ReturnsZero(){// ❌ Este test no existe o está comentado}