nunit-console
nunit-console copied to clipboard
AppDomain.CurrentDomain.BaseDirectory is directory nunit-agent.exe
Hello! I think you are aware of this behavior. But just in case, one more time.
When running a test from nunit3-console. The value of AppDomain.CurrentDomain.BaseDirectory in the test will be the path to the directory from where the console runner is essentially launched.
I have seen many people mention this feature in issues. But I didn't see any workaround for this. I can't use TestContext because the call to AppDomain.CurrentDomain.BaseDirectory is used in a third-party library.
About csproj:
- net6.0
- nuget Nunit v3.13.3
- nuget NUnit3TestAdapter v4.3.1
Command
C:\NUnit.Console-3.16.2\bin\nunit3-console.exe C:\src\solution\Ttest.Project\bin\Test.Project.dll --where id=1-1002
Value of AppDomain.CurrentDomain.BaseDirectory
C:\NUnit.Console-3.16.2\bin\agents\net6.0\
Questions:
- Please let me know if there is a workaround.
- Are there any plans to fix this behavior?
There are not workarounds?
Can you explain a bit about what you are trying to accomplish by changing the base directory and what you've tried so far? We'll need a bit more info to better understand and help.
As a general piece of advice, there are some work arounds and code samples listed in here which may help for your use case: https://github.com/nunit/nunit/issues/1072
And there's some command line options which may help depending on what you're trying to do (for example, --work
or --out
) : https://docs.nunit.org/articles/nunit/running-tests/Console-Command-Line.html
@stevenaw NUnit traditionally ran tests in a separate AppDomain, which it created. The .NET Framework agents still do that. You can find the key code in the DomainManager
class. That class is only built for .NET Framework. The .NET Core agents all run tests in the primary AppDomain.
Historically, this is due to the fact that our first runners for .NET Core were dealing with versions 1.0 and 1.1, where almost none of the features of AppDomain
were available. Research is needed to figure out a way to set a separate base directory for the tests run by a .NET Core agent and resolve this. It may be through AppDomain
or possibly in some other way.
I'm going to create an identical issue to this one in the TestCentric Gui because the same problem exists there. I'll post or link here if I figure something out. If you take this on, feel free to consult me offline.
I'm wondering why a .NET 6.0 test assembly, is expecting there to be more than one AppDomain in a process... i.e. the primary AppDomain. Perhaps this is not a bug at all.
Is this an x/y problem? Why do you need the ApplicationBase to match the current test assembly?
We have switched to dotnet test where the behaviour is still correct.
I'm pretty much convinced that this is not a bug.
- AppDomains are somewhat minimally supported in .NET Core. In particular, they cannot be created.
- As a result, all code runs in the primary AppDomain of the process hosting it.
- Consequently, no .NET Core test assembly being executed by a test runner should expect the ApplicationBase to be anything other than that of the primary AppDomain.
- In addition, any assembly referenced by the test assembly will also be a .NET Core or Standard assembly, so the same limitations apply to it.
@OsirisTerje I'm inclined to close this. Do you want any others on the team to review it first?
Personally, I think it is fine to close this issue