NUnit: A parameter-to-string conversion exception prevents the test from being reported
delatrie opened this issue · 6 comments
I'm submitting a ...
- bug report
- feature request
- support request => Please do not submit support request here, see note at the top of this template.
What is the current behavior?
If an argument of a parametrized test can't be serialized to JSON, the test is missing in the report. Additionally, a context exception occurs masking the original problem.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
Given the test:
using System;
using System.Collections.Generic;
using NUnit.Allure.Core;
using NUnit.Framework;
[AllureNUnit]
class MyClass
{
[Test]
[TestCaseSource(typeof(MyClass), nameof(GetActions))]
public void MyTest(Action action)
{
}
public static List<Action> GetActions() => new()
{
() => {}
};
}
When we run it with NUnit, the test result file is not generated. The following exception is shown by NUnit:
Message:
System.InvalidOperationException : No fixture, test, or step context is active.
Stack Trace:
AllureContext.get_CurrentStepContainer() line 174
AllureLifecycle.UpdateExecutableItem(Action`1 updateItem) line 570
AllureApi.AddAttachment(String name, String type, Byte[] content, String fileExtension) line 407
AllureNUnitHelper.AddConsoleOutputAttachment() line 303
AllureNUnitHelper.StopTestCase() line 62
<>c__DisplayClass4_0.<AfterTest>b__0() line 55
AllureNUnitAttribute.RunHookInRestoredAllureContext(ITest test, Action action) line 102
AllureNUnitAttribute.AfterTest(ITest test) line 49
<.ctor>b__1(TestExecutionContext context)
<>c__DisplayClass1_0.<Execute>b__1()
DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
If we debug the test, the following exception can be observed first:
Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Self referencing loop detected for property 'Module' with type 'System.Reflection.RuntimeModule'. Path 'Method.Module.Assembly.EntryPoint'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)
What is the expected behavior?
No exception is thrown, the test passes and the result is generated.
Please tell us about your environment:
- Test framework: NUnit@3.13.3
- Allure adapter: Allure.NUnit@2.11.0
Other information
An obvious thing to do is to fall back to type names in case of serialization errors. Additionally, we may check in advance if a type can be serialized (e.g., delegates can not).
Hi! when it's going to be fixed?
Hi! when it's going to be fixed?
Same question here. The issue prevents us from using the latest version of the package.
Has the problem been solved? The [Skip] attribute didn't help me
Sorry for the delay. The issue is fixed in the new 2.12.0 release.