From a8889fcabb937fd562a0e59c0b5f6e76c14198d3 Mon Sep 17 00:00:00 2001 From: Berg Date: Mon, 18 Oct 2021 21:25:21 +0200 Subject: [PATCH] Uses TestExecutionContext to get the current test, instead of trying to find it using assembly scanning --- .../Testing/TestOptionAttributeBase.cs | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs b/tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs index 1e62f1827c28..a5a4c2ff410a 100644 --- a/tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs +++ b/tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs @@ -6,12 +6,14 @@ using System.Linq; using System.Reflection; using NUnit.Framework; +using NUnit.Framework.Internal; using Umbraco.Cms.Core.Exceptions; namespace Umbraco.Cms.Tests.Common.Testing { public abstract class TestOptionAttributeBase : Attribute { + [Obsolete("This is not used anymore - Test classes are found using nunit helpers")] public static readonly List ScanAssemblies = new List(); public static TOptions GetTestOptions(MethodInfo method) @@ -29,26 +31,8 @@ public static TOptions GetTestOptions() where TOptions : TestOptionAttributeBase, new() { TestContext.TestAdapter test = TestContext.CurrentContext.Test; - var typeName = test.ClassName; var methodName = test.MethodName; - - // This will only get types from whatever is already loaded in the app domain. - var type = Type.GetType(typeName, false); - if (type == null) - { - // automatically add the executing and calling assemblies to the list to scan for this type - var scanAssemblies = ScanAssemblies.Union(new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }).ToList(); - - type = scanAssemblies - .Select(assembly => assembly.GetType(typeName, false)) - .FirstOrDefault(x => x != null); - if (type == null) - { - throw new PanicException($"Could not resolve the running test fixture from type name {typeName}.\n" + - $"To use base classes from Umbraco.Tests, add your test assembly to TestOptionAttributeBase.ScanAssemblies"); - } - } - + var type = TestExecutionContext.CurrentContext.TestObject.GetType(); MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads? TOptions options = GetTestOptions(methodInfo); return options;