Skip to content

Commit a4272e0

Browse files
committed
improve CoverageResultTaskTests
1 parent b905efe commit a4272e0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

test/coverlet.msbuild.tasks.tests/CoverageResultTaskTests.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void Execute_StateUnderTest_MissingInstrumentationState()
7070
}
7171

7272
[Fact]
73-
public void Execute_StateUnderTest_WithInstrumentationState_Fake()
73+
public void Execute_StateUnderTest_WithInstrumentationState_ThresholdType()
7474
{
7575
// Arrange
7676
var mockFileSystem = new Mock<IFileSystem>();
@@ -89,18 +89,15 @@ public void Execute_StateUnderTest_WithInstrumentationState_Fake()
8989
BaseTask.ServiceProvider = serviceProvider;
9090
_buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => _errors.Add(e));
9191

92-
#pragma warning disable CS8604 // Possible null reference argument for parameter..
93-
#pragma warning disable CS8602 // Dereference of a possibly null reference.
94-
var InstrumenterState = new TaskItem(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "TestAssets\\InstrumenterState.ItemSpec.data1.xml"));
95-
#pragma warning restore CS8602 // Dereference of a possibly null reference.
96-
#pragma warning restore C8S604 // Possible null reference argument for parameter.
92+
var baseDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase ?? string.Empty;
93+
var InstrumenterState = new TaskItem(Path.Combine(baseDirectory, "TestAssets\\InstrumenterState.ItemSpec.data1.xml"));
9794

9895
var coverageResultTask = new CoverageResultTask
9996
{
10097
OutputFormat = "cobertura",
10198
Output = "coverageDir",
10299
Threshold = "50",
103-
ThresholdType = "total",
100+
ThresholdType = "line,branch,method",
104101
ThresholdStat = "total",
105102
InstrumenterState = InstrumenterState
106103
};
@@ -110,12 +107,18 @@ public void Execute_StateUnderTest_WithInstrumentationState_Fake()
110107
bool success = coverageResultTask.Execute();
111108

112109
// Assert
113-
Assert.True(success);
114-
Assert.False(coverageResultTask.Log.HasLoggedErrors);
110+
Assert.False(success);
111+
Assert.True(coverageResultTask.Log.HasLoggedErrors);
112+
113+
// Verify the error message
114+
string expectedErrorMessage = "The total line coverage is below the specified 50\r\n" +
115+
"The total branch coverage is below the specified 50\r\n" +
116+
"The total method coverage is below the specified 50";
117+
118+
Assert.Contains(expectedErrorMessage, _errors[0].Message);
115119

116120
Assert.Contains("coverageDir.cobertura.xml", coverageResultTask.ReportItems[0].ItemSpec);
117121
Assert.Equal(16, coverageResultTask.ReportItems[0].MetadataCount);
118-
119122
}
120123

121124
}

0 commit comments

Comments
 (0)