Nunit 3.16.0 sets incorrect AppDomain.CurrentDomain.BaseDirectory

TeamCity Professional 2022.10.1 (build 116934)

When running tests using the new Nunit 3.16.0 in combination with a .net 7.0 test dll the AppDomain.CurrentDomain.BaseDirectory isn't set correctly.

Its set to the Nunit agents folder instead of the build directory containing the test dll. 

C:\BuildAgent\tools\NUnit.Console.3.16.0\agents\net7.0\

It sound fairly similar to this problem:

https://youtrack.jetbrains.com/issue/RIDER-20768

 

 

0
7 comments

Problem persist in 3.16.1 of nunit

0

Hello Niels!

Sorry about the delayed response here. Can you please share a build log for any build that shows the problem (so that I could try to reproduce the issue)? You may upload it in a private manner using uploads.jetbrains.com site - just let me know the upload ID when done so I can access it. 

0

I've created a workaround for it already a couple of weeks ago, I don't have buildlogs that old anymore. 

But just do "string applicationRootFolder = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);"

in any nunit test running <TargetFramework>net7.0-windows</TargetFramework> and you will get two completely different results when running that same test in Visual Studio Test Explorer and when running it via TeamCity NUnit runner. With the TeamCity one having "C:\BuildAgent\tools\NUnit.Console.3.16.0\agents\net7.0\" as the root while in Visual Studio Test Explorer it being the normal bin folder. 

 

0

Hi Niels. The behavior in TeamCity runner is consistent with the behavior of nunit3-console.exe. When I manually run NUnit console using the command <NUnit_Console_dir>\bin\nunit3-console.exe <project_dir>\bin\Debug\net6.0\<test_assembly>.dllPath.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) resolves into <NUnit_Console_dir>\bin\agents\net6.0. TeamCity runs a similar command, and the output is similar, so I don't see why this is a problem. Could you please explain why you think it is?

0

In the .net framework 4.7.2 version that same "Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)" call would return the location of the test dll.

Something you would expect when the code is running outside the test environment. Maybe that is something that changed with the switch to dotnet core? but it's annoying that the code behaves differently when run in a test environment compared to being run as a program.

It's also strange that the Visual Studio Test Explorer doesn't have this behaviour. There the "Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)" resolves to the test dll location. Making test that succeed in VS fail on teamcity.

 

 

 

 

0
You can run the tests using the .NET runner instead of the NUnit console runner. It should yield the same result as Visual Studio Test Explorer. Would that help?
0

I've switched over to the dotnet vstest runner for other build projects. WPF (.net 7) referencing code also don't seem to work correctly with the nunit console runner. 

Gone ditch the NUnit console runner for future builds.

 

0

Please sign in to leave a comment.