-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NUnit.Engine 3.18.3 value of Attribute static property is null #1514
Comments
The problem here is that the static value in the framework is not the same value set by your runner program. Statics have individual values in each AppDomain and that behavior seems to persist to an extent under .NET Core. To demonstrate this behavior, you can initialize the static property at it's point of declaration, so...
You appear to be attempting to overcome a long-standing design feature (limitation?) of the nunit framework. Defining and loading of tests takes place before they are executed and that definition may not be subsequently changed. I think we have a bit of an X/Y problem here. If you could formulate a question that relates to what you are trying to accomplish, we may be able to offer other suggestions. |
Thanks for your reply but according to the docs .NET Core has exactly one AppDomain only:
https://learn.microsoft.com/en-us/dotnet/api/system.appdomain?view=net-8.0#remarks Furthermore, given what you've said, I don't understand why the test runs successfully with version 3.18.1 and 3.18.2. To drill down, I added the following: var fileInfo = new FileInfo(args[0]);
// Load into the default AssemblyLoadContext.
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(fileInfo.FullName);
var testType = assembly.GetType("AspectService.Tests.Tests");
var attribute = testType!.GetCustomAttribute<NUnitAspectAttribute>();
var attributeType = attribute!.GetType();
if (attributeType != null)
{
var staticProperty = attributeType.GetProperty("StaticProperty", BindingFlags.Public | BindingFlags.Static);
if (staticProperty != null)
{
var staticPropertyValue = staticProperty.GetValue(null);
Console.WriteLine($"NUnitAspectAttribute.StaticProperty: [{staticPropertyValue}]");
}
else
{
Console.WriteLine("StaticProperty not found on NUnitAspectAttribute.");
}
}
else
{
Console.WriteLine("NUnitAspectAttribute type not found in the assembly.");
}
using var engine = new TestEngine();
engine.WorkDirectory = fileInfo.DirectoryName;
engine.InternalTraceLevel = InternalTraceLevel.Debug;
engine.Initialize(); This outputs (as I would expect, interestingly also for version 3.18.3):
To be pedantic I even added a test that checks that the NUnit and Aspect* assemblies are in the same default assembly load context. So I don't understand why NUnit can't "see" the current value of the static property. It's all rather odd. Perhaps trying to explain why I'm doing this might help to find a solution; so here goes: We have an ASP.NET application that loads plugins; these plugins provide a REST API. Does that make the issue clearer? EnvironmentDocker container running in WSL. .NET SDK: Runtime Environment: |
I'm re-opening to examine the question of what changed between releases. Please let me know exactly what engine package you installed for both 3.18.2 and 3.18.3. There are, in fact some differences in what you get from various packages, which I hope to eliminate in 3.19. WRT AppDomain under .NET Core, I'm familiar with what Microsoft says about them but skepticism about MS published docs has paid off for me in the past. In this case, I ask "One appdomain per what?" Process? Planet? Something in between? :-) Your extra test is far from pedantic and tells us a lot. Thanks for explaining the use case. |
Thanks @CharliePoole, here's the requested package versions of
|
There is a regression in the NUnit.Engine version 3.18.3 which we use as an NuGet dependency.
To help demonstrate the issue I have created an example project here on GitHub: trysetnull/nunit-engine-bug
The steps are as follows:
With NUnit.Engine versions 3.18.1 and 3.18.2, at point 3 the value of the static property is what has been set at step 1.
The example project has a README with more information.
The text was updated successfully, but these errors were encountered: