Closed
Description
As commented on #2922 an issues seems to be introduced in NUnit 3.10 that prevents the tests running on Blazor/WASM.
I see the problem is in SandboxedThreadState.Capture
where Thread.CurrentPrincipal
is being red on netstandard2.0 and throws the exception (see below) that the Operation is not supported.
Code like this
public class TestRunner : TestFilter, ITestListener
{
public IJSRuntime JS { get; }
public TestRunner(IJSRuntime js) => JS = js ?? throw new ArgumentNullException(nameof(js));
public void Run()
{
Console.WriteLine("Starting tests");
Console.WriteLine();
var builder = new DefaultTestAssemblyBuilder();
var runner = new NUnitTestAssemblyRunner(builder);
runner.Load(typeof(TestRunner).Assembly, new Dictionary<string, object>()
{
//https://github.com/nunit/nunit/issues/2922
[FrameworkPackageSettings.NumberOfTestWorkers] = 0,
[FrameworkPackageSettings.SynchronousEvents] = true,
// [FrameworkPackageSettings.RunOnMainThread] = true
});
runner.Run(this, this);
Console.WriteLine();
Console.WriteLine("Test run finished");
}
#region ITestListener
public void TestStarted(ITest test) => Console.WriteLine("Running " + test.FullName);
public void TestFinished(ITestResult result)
{
var symbol = result.FailCount > 0 ? "✖" : (result.PassCount > 0 ? "✔" : "❓");
Console.WriteLine($"\t{symbol}{result.PassCount} passed, {result.FailCount} failed, {result.SkipCount} skipped");
}
public void TestOutput(TestOutput output) => Console.WriteLine("\t🖶" + output.Text);
//public void SendMessage(TestMessage message) => Console.WriteLine("\t🛈" + message.Message);
#endregion
#region TestFilter
//See NUnit.Framework.Internal.TestFilter+EmptyFilter
public override bool Match(ITest test) => true;
public override TNode AddToXml(TNode parentNode, bool recursive) => parentNode.AddElement("filter");
public override bool Pass(ITest test) => true;
public override bool IsExplicitMatch(ITest test) => false;
#endregion
}
Fails like this:
WASM: System.AggregateException: One or more errors occurred. (Operation is not supported on this platform.) ---> System.PlatformNotSupportedException: Operation is not supported on this platform. blazor.webassembly.js:1:35073
WASM: at System.Threading.Thread.get_CurrentPrincipal () <0x20559e8 + 0x00008> in <c2e6bcfe48324efd8e0e56b33265ed38>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.SandboxedThreadState.Capture () <0x20556a0 + 0x00008> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.TestExecutionContext.UpdateContextFromEnvironment () <0x20554b8 + 0x00004> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.TestExecutionContext..ctor () <0x2054f40 + 0x0006c> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.CreateTestExecutionContext (NUnit.Framework.Interfaces.ITestListener listener) <0x2054338 + 0x00006> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.RunAsync (NUnit.Framework.Interfaces.ITestListener listener, NUnit.Framework.Interfaces.ITestFilter filter) <0x204df28 + 0x0007e> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.Run (NUnit.Framework.Interfaces.ITestListener listener, NUnit.Framework.Interfaces.ITestFilter filter) <0x204d840 + 0x0000c> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at Doers.HtmlDom.Tests.InBrowser.TestRunner.Run () <0x1f93920 + 0x00098> in <5e269b296ac844bb952f344e9d495791>:0 blazor.webassembly.js:1:35073
WASM: at Doers.HtmlDom.Tests.InBrowser.Startup.Configure (Microsoft.AspNetCore.Components.Builder.IComponentsApplicationBuilder app) <0x1f93060 + 0x00028> in <5e269b296ac844bb952f344e9d495791>:0 blazor.webassembly.js:1:35073
WASM: at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) blazor.webassembly.js:1:35073
WASM: at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1e846c0 + 0x000d2> in <c2e6bcfe48324efd8e0e56b33265ed38>:0 blazor.webassembly.js:1:35073
WASM: --- End of stack trace from previous location where exception was thrown --- blazor.webassembly.js:1:35073
WASM: blazor.webassembly.js:1:35073
WASM: at Microsoft.AspNetCore.Blazor.Hosting.ConventionBasedStartup.Configure (Microsoft.AspNetCore.Components.Builder.IComponentsApplicationBuilder app, System.IServiceProvider services) <0x1f8b100 + 0x000fa> in <28660ebc37c240c28a4ee41c6477f236>:0 blazor.webassembly.js:1:35073
WASM: at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHost.StartAsyncAwaited () <0x1f8a258 + 0x001e8> in <28660ebc37c240c28a4ee41c6477f236>:0 blazor.webassembly.js:1:35073
WASM: --- End of inner exception stack trace --- blazor.webassembly.js:1:35073
WASM: ---> (Inner Exception #0) System.PlatformNotSupportedException: Operation is not supported on this platform. blazor.webassembly.js:1:35073
WASM: at System.Threading.Thread.get_CurrentPrincipal () <0x20559e8 + 0x00008> in <c2e6bcfe48324efd8e0e56b33265ed38>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.SandboxedThreadState.Capture () <0x20556a0 + 0x00008> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.TestExecutionContext.UpdateContextFromEnvironment () <0x20554b8 + 0x00004> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Internal.TestExecutionContext..ctor () <0x2054f40 + 0x0006c> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.CreateTestExecutionContext (NUnit.Framework.Interfaces.ITestListener listener) <0x2054338 + 0x00006> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.RunAsync (NUnit.Framework.Interfaces.ITestListener listener, NUnit.Framework.Interfaces.ITestFilter filter) <0x204df28 + 0x0007e> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at NUnit.Framework.Api.NUnitTestAssemblyRunner.Run (NUnit.Framework.Interfaces.ITestListener listener, NUnit.Framework.Interfaces.ITestFilter filter) <0x204d840 + 0x0000c> in <d392db2fb3d64f4fa564a7b744fc7801>:0 blazor.webassembly.js:1:35073
WASM: at Doers.HtmlDom.Tests.InBrowser.TestRunner.Run () <0x1f93920 + 0x00098> in <5e269b296ac844bb952f344e9d495791>:0 blazor.webassembly.js:1:35073
WASM: at Doers.HtmlDom.Tests.InBrowser.Startup.Configure (Microsoft.AspNetCore.Components.Builder.IComponentsApplicationBuilder app) <0x1f93060 + 0x00028> in <5e269b296ac844bb952f344e9d495791>:0 blazor.webassembly.js:1:35073
WASM: at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) blazor.webassembly.js:1:35073
WASM: at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1e846c0 + 0x000d2> in <c2e6bcfe48324efd8e0e56b33265ed38>:0 blazor.webassembly.js:1:35073
WASM: --- End of stack trace from previous location where exception was thrown --- blazor.webassembly.js:1:35073
WASM: blazor.webassembly.js:1:35073
WASM: at Microsoft.AspNetCore.Blazor.Hosting.ConventionBasedStartup.Configure (Microsoft.AspNetCore.Components.Builder.IComponentsApplicationBuilder app, System.IServiceProvider services) <0x1f8b100 + 0x000fa> in <28660ebc37c240c28a4ee41c6477f236>:0 blazor.webassembly.js:1:35073
WASM: at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHost.StartAsyncAwaited () <0x1f8a258 + 0x001e8> in <28660ebc37c240c28a4ee41c6477f236>:0 <--- blazor.webassembly.js:1:35073
WASM: blazor.webassembly.js:1:35073