Skip to content

Commit 9494591

Browse files
authored
Merge pull request #11403 from umbraco/v9/feature/improve_package_usage_of_integration_tests
Simplify usage of integration tests from nuget package
2 parents c77dc5d + edaf411 commit 9494591

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using System.Linq;
77
using System.Reflection;
88
using NUnit.Framework;
9+
using NUnit.Framework.Internal;
910
using Umbraco.Cms.Core.Exceptions;
1011

1112
namespace Umbraco.Cms.Tests.Common.Testing
1213
{
1314
public abstract class TestOptionAttributeBase : Attribute
1415
{
16+
[Obsolete("This is not used anymore - Test classes are found using nunit helpers")]
1517
public static readonly List<Assembly> ScanAssemblies = new List<Assembly>();
1618

1719
public static TOptions GetTestOptions<TOptions>(MethodInfo method)
@@ -29,26 +31,8 @@ public static TOptions GetTestOptions<TOptions>()
2931
where TOptions : TestOptionAttributeBase, new()
3032
{
3133
TestContext.TestAdapter test = TestContext.CurrentContext.Test;
32-
var typeName = test.ClassName;
3334
var methodName = test.MethodName;
34-
35-
// This will only get types from whatever is already loaded in the app domain.
36-
var type = Type.GetType(typeName, false);
37-
if (type == null)
38-
{
39-
// automatically add the executing and calling assemblies to the list to scan for this type
40-
var scanAssemblies = ScanAssemblies.Union(new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }).ToList();
41-
42-
type = scanAssemblies
43-
.Select(assembly => assembly.GetType(typeName, false))
44-
.FirstOrDefault(x => x != null);
45-
if (type == null)
46-
{
47-
throw new PanicException($"Could not resolve the running test fixture from type name {typeName}.\n" +
48-
$"To use base classes from Umbraco.Tests, add your test assembly to TestOptionAttributeBase.ScanAssemblies");
49-
}
50-
}
51-
35+
var type = TestExecutionContext.CurrentContext.TestObject.GetType();
5236
MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
5337
TOptions options = GetTestOptions<TOptions>(methodInfo);
5438
return options;

0 commit comments

Comments
 (0)