Skip to content

Commit

Permalink
Merge pull request #11403 from umbraco/v9/feature/improve_package_usa…
Browse files Browse the repository at this point in the history
…ge_of_integration_tests

Simplify usage of integration tests from nuget package
  • Loading branch information
Zeegaan authored Oct 20, 2021
2 parents c77dc5d + edaf411 commit 9494591
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions tests/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Assembly> ScanAssemblies = new List<Assembly>();

public static TOptions GetTestOptions<TOptions>(MethodInfo method)
Expand All @@ -29,26 +31,8 @@ public static TOptions GetTestOptions<TOptions>()
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<TOptions>(methodInfo);
return options;
Expand Down

0 comments on commit 9494591

Please sign in to comment.