diff --git a/test/dotnet-test-rerun.IntegrationTests/DotNetTestRerunTests.cs b/test/dotnet-test-rerun.IntegrationTests/DotNetTestRerunTests.cs index 927e532..4efe9da 100644 --- a/test/dotnet-test-rerun.IntegrationTests/DotNetTestRerunTests.cs +++ b/test/dotnet-test-rerun.IntegrationTests/DotNetTestRerunTests.cs @@ -34,7 +34,7 @@ public async Task DotnetTestRerun_RunXUnitExample_Success() // Assert output.Should().Contain("Passed!", Exactly.Once()); - output.Should().NotContainAny(new string[] {"Failed!", "Rerun attempt"}); + output.Should().NotContainAny(new string[] { "Failed!", "Rerun attempt" }); Environment.ExitCode.Should().Be(0); IsThereACoverageFile().Should().BeFalse(); } @@ -46,11 +46,12 @@ public async Task DotnetTestRerun_RunMSTestExample_Success() Environment.ExitCode = 0; // Act - var output = await RunDotNetTestRerunAndCollectOutputMessage("MSTestExample", "--collect \"XPlat Code Coverage\" --configuration \"debug\" --verbosity \"minimal\""); + var output = await RunDotNetTestRerunAndCollectOutputMessage("MSTestExample", + "--collect \"XPlat Code Coverage\" --configuration \"debug\" --verbosity \"minimal\""); // Assert output.Should().Contain("Passed!", Exactly.Once()); - output.Should().NotContainAny(new string[] {"Failed!", "Rerun attempt"}); + output.Should().NotContainAny(new string[] { "Failed!", "Rerun attempt" }); output.Should().Contain("-c \"debug\" -v \"Minimal\""); Environment.ExitCode.Should().Be(0); IsThereACoverageFile().Should().BeTrue(); @@ -58,7 +59,7 @@ public async Task DotnetTestRerun_RunMSTestExample_Success() [Fact] public async Task DotnetTestRerun_RunMSTestExample_RunningProcess_Success() - { + { // Arrange Environment.ExitCode = 0; @@ -66,7 +67,7 @@ public async Task DotnetTestRerun_RunMSTestExample_RunningProcess_Success() Process process = new Process(); process.StartInfo.FileName = "test-rerun"; process.StartInfo.Arguments = $"{_dir}\\MSTestExample --rerunMaxAttempts 3 --results-directory {_dir}"; - + // Act process.Start(); @@ -88,7 +89,7 @@ public async Task DotnetTestRerun_FailingMSTest_Fails() output.Should().NotContain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(4)); output.Should().Contain("Rerun filter: FullyQualifiedName~MSTestExample.UnitTest1.SimpleNumberFailCompare", - Exactly.Thrice()); + Exactly.Thrice()); output.Should().Contain("Failed: 2, Passed: 6", Exactly.Once()); Environment.ExitCode.Should().Be(1); @@ -99,13 +100,13 @@ public async Task DotnetTestRerun_RunNUnitExample_Success() { // Arrange Environment.ExitCode = 0; - + // Act var output = await RunDotNetTestRerunAndCollectOutputMessage("NUnitTestExample"); // Assert output.Should().Contain("Passed!", Exactly.Once()); - output.Should().NotContainAny(new string[] {"Failed!", "Rerun attempt"}); + output.Should().NotContainAny(new string[] { "Failed!", "Rerun attempt" }); Environment.ExitCode.Should().Be(0); } @@ -114,13 +115,15 @@ public async Task DotnetTestRerun_RunNUnitExample_WithPropertiesActive_Success() { // Arrange Environment.ExitCode = 0; - + // Act - var output = await RunDotNetTestRerunAndCollectOutputMessage("NUnitTestExample", extraArgs: $"/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput={_dir}\\TestResults\\Coverage\\UnitTests-TestResults.opencover.xml"); + var output = await RunDotNetTestRerunAndCollectOutputMessage("NUnitTestExample", + extraArgs: + $"/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput={_dir}\\TestResults\\Coverage\\UnitTests-TestResults.opencover.xml"); // Assert output.Should().Contain("Passed!", Exactly.Once()); - output.Should().NotContainAny(new string[] {"Failed!", "Rerun attempt"}); + output.Should().NotContainAny(new string[] { "Failed!", "Rerun attempt" }); Environment.ExitCode.Should().Be(0); } @@ -130,13 +133,13 @@ public async Task DotnetTestRerun_RunNUnitExample_WithDeleteFiles() // Arrange var testDir = TestUtilities.GetTmpDirectory(); TestUtilities.CopyFixture(string.Empty, new DirectoryInfo(testDir)); - + // Act var output = await RunDotNetTestRerunAndCollectOutputMessage("NUnitTestExample", "--deleteReports", testDir); // Assert output.Should().Contain("Passed!", Exactly.Once()); - output.Should().NotContainAny(new string[] {"Failed!", "Rerun attempt"}); + output.Should().NotContainAny(new string[] { "Failed!", "Rerun attempt" }); var files = FileSystem.Directory.EnumerateFiles(testDir, "*trx"); files.Should().HaveCount(0); @@ -147,12 +150,12 @@ public async Task DotnetTestRerun_FailingXUnit_Fails() { // Arrange Environment.ExitCode = 0; - + // Arrange var testDir = TestUtilities.GetTmpDirectory(); TestUtilities.CopyFixture(string.Empty, new DirectoryInfo(testDir)); Environment.ExitCode = 0; - + // Act var output = await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitExample", dir: testDir); @@ -160,7 +163,7 @@ public async Task DotnetTestRerun_FailingXUnit_Fails() output.Should().NotContain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(4)); output.Should().Contain("Rerun filter: FullyQualifiedName~FailingXUnitExample.SimpleTest.SimpleStringCompare", - Exactly.Thrice()); + Exactly.Thrice()); output.Should().Contain("Passed: 4", Exactly.Once()); var files = FileSystem.Directory.EnumerateFiles(testDir, "*trx"); @@ -172,27 +175,26 @@ public async Task DotnetTestRerun_FailingXUnit_Fails() [InlineData("quiet")] [InlineData("minimal")] [InlineData("detailed")] - [InlineData("diagnostic")] + [Theory] public async Task DotnetTestRerun_FailingXUnit_WithVerbosity_Fails(string verbosity) { // Arrange Environment.ExitCode = 0; - + // Arrange var testDir = TestUtilities.GetTmpDirectory(); TestUtilities.CopyFixture(string.Empty, new DirectoryInfo(testDir)); Environment.ExitCode = 0; - + // Act - var output = await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitExample", dir: testDir, extraArgs: $"--verbosity {verbosity}"); + var output = await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitExample", dir: testDir, + extraArgs: $"--verbosity {verbosity}"); // Assert output.Should().NotContain("Passed!"); - output.Should().Contain("Failed:", Exactly.Times(4)); output.Should().Contain("Rerun filter: FullyQualifiedName~FailingXUnitExample.SimpleTest.SimpleStringCompare", - Exactly.Thrice()); - output.Should().Contain("Passed: 4", - Exactly.Once()); + Exactly.Thrice()); + output.Should().ContainAny("Passed: 4", "Passed: 4"); var files = FileSystem.Directory.EnumerateFiles(testDir, "*trx"); files.Should().HaveCount(4); Environment.ExitCode.Should().Be(1); @@ -203,18 +205,20 @@ public async Task DotnetTestRerun_FailingXUnit_WithMultipleFrameworks_Fails() { // Arrange Environment.ExitCode = 0; - + // Arrange var testDir = TestUtilities.GetTmpDirectory(); TestUtilities.CopyFixture(string.Empty, new DirectoryInfo(testDir)); Environment.ExitCode = 0; - + // Act - var output = await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitWithMultipleFrameworksExample", dir: testDir); + var output = + await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitWithMultipleFrameworksExample", dir: testDir); // Assert - output.Should().MatchRegex("Rerun filter: FullyQualifiedName~(FailingXUnitExample.)*SimpleTest.SimpleStringCompare", - Exactly.Thrice()); + output.Should().MatchRegex( + "Rerun filter: FullyQualifiedName~(FailingXUnitExample.)*SimpleTest.SimpleStringCompare", + Exactly.Thrice()); output.Should().Contain("Passed: 1", Exactly.Once()); output.Should().Contain("Failed!", Exactly.Times(4)); @@ -233,7 +237,7 @@ public async Task DotnetTestRerun_FailingXUnit_RunningProcess_Fails() Process process = new Process(); process.StartInfo.FileName = "test-rerun"; process.StartInfo.Arguments = $"{_dir}\\FailingXUnitExample --rerunMaxAttempts 3 --results-directory {_dir}"; - + // Act process.Start(); @@ -247,11 +251,11 @@ public async Task DotnetTestRerun_RunNonExistentXUnitProject_MissingArguments_Fa { // Arrange Environment.ExitCode = 0; - + Process process = new Process(); process.StartInfo.FileName = "test-rerun"; process.StartInfo.Arguments = $"{_dir}\\XUnitThatDoesNotExist --rerunMaxAttempts 3 --results-directory {_dir}"; - + // Act process.Start(); @@ -272,8 +276,9 @@ public async Task DotnetTestRerun_FailingMultipleXUnit_Fails() // Assert output.Should().NotContain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(4)); - output.Should().Contain("Rerun filter: FullyQualifiedName~FailingXUnitExample.SimpleTest.SimpleFailedNumberCompare", - Exactly.Thrice()); + output.Should().Contain( + "Rerun filter: FullyQualifiedName~FailingXUnitExample.SimpleTest.SimpleFailedNumberCompare", + Exactly.Thrice()); output.Should().Contain("Failed: 2, Passed: 5", Exactly.Once()); Environment.ExitCode.Should().Be(1); @@ -292,7 +297,7 @@ public async Task DotnetTestRerun_FailingNUnit_PassOnSecond() output.Should().Contain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(1)); output.Should().Contain("Rerun filter: FullyQualifiedName~NUnitTestExample.Tests.SecondSimpleNumberCompare", - Exactly.Once()); + Exactly.Once()); output.Should().Contain("Failed: 1, Passed: 1", Exactly.Once()); Environment.ExitCode.Should().Be(0); @@ -311,20 +316,21 @@ public async Task DotnetTestRerun_FailingNUnit_PassOnSecond_WithCategory() // Assert output.Should().Contain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(1)); - output.Should().Contain("Rerun filter: (TestCategory=FirstCategory|TestCategory=SecondCategory)&(FullyQualifiedName~NUnitTestExample.Tests.SecondSimpleNumberCompare)", - Exactly.Once()); + output.Should().Contain( + "Rerun filter: (TestCategory=FirstCategory|TestCategory=SecondCategory)&(FullyQualifiedName~NUnitTestExample.Tests.SecondSimpleNumberCompare)", + Exactly.Once()); output.Should().Contain("Failed: 1, Passed: 1", Exactly.Once()); Environment.ExitCode.Should().Be(0); } - + [Fact] public async Task DotnetTestRerun_FailingXUnit_WithDeleteFiles() { // Arrange var testDir = TestUtilities.GetTmpDirectory(); TestUtilities.CopyFixture(string.Empty, new DirectoryInfo(testDir)); - + // Act var output = await RunDotNetTestRerunAndCollectOutputMessage("FailingXUnitExample", "--deleteReports", testDir); @@ -332,14 +338,14 @@ public async Task DotnetTestRerun_FailingXUnit_WithDeleteFiles() output.Should().NotContain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(4)); output.Should().Contain("Rerun filter: FullyQualifiedName~FailingXUnitExample.SimpleTest.SimpleStringCompare", - Exactly.Thrice()); + Exactly.Thrice()); output.Should().Contain("Passed: 4", Exactly.Once()); var files = FileSystem.Directory.EnumerateFiles(testDir, "*trx"); files.Should().HaveCount(0); } - + [Fact] public async Task DotnetTestRerun_FailingNUnit_PassOnSecond_TwoFailingProjects() { @@ -355,9 +361,9 @@ public async Task DotnetTestRerun_FailingNUnit_PassOnSecond_TwoFailingProjects() output.Should().Contain("Rerun filter:", Exactly.Twice()); output.Should().Contain("Failed: 2, Passed: 1", - Exactly.Once()); + Exactly.Once()); output.Should().Contain("Failed: 1, Passed: 1", - Exactly.Twice()); + Exactly.Twice()); output.Should().Contain("Failed: 0, Passed: 1", Exactly.Twice()); Environment.ExitCode.Should().Be(0); @@ -375,16 +381,18 @@ public async Task DotnetTestRerun_FailingNUnit_PassOnSecond_WithFailingTestWithS // Assert output.Should().Contain("Passed!"); output.Should().Contain("Failed!", Exactly.Times(1)); - output.Should().Contain("Rerun filter: FullyQualifiedName~NUnitTestExample.SimpleTest.SecondSimpleNumberCompare", - Exactly.Once()); + output.Should().Contain( + "Rerun filter: FullyQualifiedName~NUnitTestExample.SimpleTest.SecondSimpleNumberCompare", + Exactly.Once()); output.Should().Contain("Failed: 1, Passed: 2", - Exactly.Once()); + Exactly.Once()); output.Should().Contain("Failed: 0, Passed: 1", Exactly.Once()); Environment.ExitCode.Should().Be(0); } - private async Task RunDotNetTestRerunAndCollectOutputMessage(string proj, string extraArgs = "", string? dir = null) + private async Task RunDotNetTestRerunAndCollectOutputMessage(string proj, string extraArgs = "", + string? dir = null) { var testDir = dir ?? _dir; var stringWriter = new StringWriter(); @@ -397,7 +405,8 @@ private async Task RunDotNetTestRerunAndCollectOutputMessage(string proj rerunCommandConfiguration.Set(command); ParseResult result = - new Parser(command).Parse($"{testDir}\\{proj} --rerunMaxAttempts 3 --results-directory {testDir} {extraArgs}"); + new Parser(command).Parse( + $"{testDir}\\{proj} --rerunMaxAttempts 3 --results-directory {testDir} {extraArgs}"); InvocationContext context = new(result); rerunCommandConfiguration.GetValues(context); @@ -415,5 +424,5 @@ private async Task RunDotNetTestRerunAndCollectOutputMessage(string proj } private static bool IsThereACoverageFile() - => Directory.GetFiles(_dir, "*cobertura.xml", SearchOption.AllDirectories).Any(); + => Directory.GetFiles(_dir, "*cobertura.xml", SearchOption.AllDirectories).Any(); } \ No newline at end of file