From 502d71d8492a5c12acf15ea00218d5ca5da7db7e Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Sun, 21 Jul 2024 01:12:56 -0300 Subject: [PATCH] Take into account duplicate FQN from theories --- src/Sample/UnitTest1.cs | 8 ++++++++ src/dotnet-retest/RetestCommand.cs | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Sample/UnitTest1.cs b/src/Sample/UnitTest1.cs index a3176bc..e3f5f04 100644 --- a/src/Sample/UnitTest1.cs +++ b/src/Sample/UnitTest1.cs @@ -2,6 +2,14 @@ namespace Sample; public class UnitTest1 { + [Theory] + [InlineData(1)] + [InlineData(2)] + public void Test1(int value) + { + Assert.True(value > 0); + } + [Fact] public void FailsOnce() { diff --git a/src/dotnet-retest/RetestCommand.cs b/src/dotnet-retest/RetestCommand.cs index e40d5a8..12c1eb2 100644 --- a/src/dotnet-retest/RetestCommand.cs +++ b/src/dotnet-retest/RetestCommand.cs @@ -170,7 +170,13 @@ Dictionary GetTestResults(string path) var isFailed = result.Attribute("outcome")?.Value == "Failed"; var method = doc.CssSelectElement($"UnitTest[id={id}] TestMethod"); Debug.Assert(method != null); - outcomes.Add($"{method.Attribute("className")?.Value}.{method.Attribute("name")?.Value}", isFailed); + // NOTE: we may have duplicate test FQN due to theories, which we'd run again in this case. + // Eventually, we might want to figure out how to filter theories in a cross-framework compatible + // way, but for now, filtering by FQN should be enough, even if not 100% optimal. + var fqn = $"{method.Attribute("className")?.Value}.{method.Attribute("name")?.Value}"; + if (!outcomes.TryGetValue(fqn, out var wasFailed) || !wasFailed) + // Only change the outcome if it was not already failed + outcomes[fqn] = isFailed; } } }