From 7f5b67847e1413a7a1ecbdbef0035f54b801cb20 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 11 May 2024 19:42:21 +1000 Subject: [PATCH] . --- .../TestFrameworks/FrameworkAssertReporter.cs | 2 +- .../Reporters/TestFrameworks/NUnit4Reporter.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ApprovalTests/Reporters/TestFrameworks/FrameworkAssertReporter.cs b/src/ApprovalTests/Reporters/TestFrameworks/FrameworkAssertReporter.cs index 5e2c94dd..c821a6d6 100644 --- a/src/ApprovalTests/Reporters/TestFrameworks/FrameworkAssertReporter.cs +++ b/src/ApprovalTests/Reporters/TestFrameworks/FrameworkAssertReporter.cs @@ -7,8 +7,8 @@ public class FrameworkAssertReporter : FirstWorkingReporter public FrameworkAssertReporter() : base( MsTestReporter.INSTANCE, - NUnit3Reporter.INSTANCE, NUnit4Reporter.INSTANCE, + NUnit3Reporter.INSTANCE, XUnit2Reporter.INSTANCE) { } diff --git a/src/ApprovalTests/Reporters/TestFrameworks/NUnit4Reporter.cs b/src/ApprovalTests/Reporters/TestFrameworks/NUnit4Reporter.cs index f65e07e1..f4d8cf48 100644 --- a/src/ApprovalTests/Reporters/TestFrameworks/NUnit4Reporter.cs +++ b/src/ApprovalTests/Reporters/TestFrameworks/NUnit4Reporter.cs @@ -3,6 +3,22 @@ namespace ApprovalTests.Reporters.TestFrameworks; public class NUnit4Reporter : AssertReporter { public readonly static NUnit4Reporter INSTANCE = new(); + static readonly Lazy isNUnit4 = new(IsisNUnit4); + + static bool IsisNUnit4() + { + return AppDomain + .CurrentDomain + .GetAssemblies() + .Any(_ => + { + var name = _.FullName; + return name.Contains("nunit.framework.legacy"); + }); + } + + public override bool IsWorkingInThisEnvironment(string forFile) => + base.IsWorkingInThisEnvironment(forFile) && isNUnit4.Value; public NUnit4Reporter() : base("NUnit.Framework.Legacy.ClassicAssert, nunit.framework.legacy", "AreEqual", NUnitStackTraceParser.Attribute)