nunit-console icon indicating copy to clipboard operation
nunit-console copied to clipboard

Cannot get configfile parameter to work

Open Roemer opened this issue 2 years ago • 7 comments

I am trying to get a test running that uses an app.config file for values.

The project is very simple: Just a .NET 5.0 library project with an app.config with connection strings and a test that tries to read them. I've also attached that project here: TestLibrary.zip

The project can be compiled with dotnet build TestLibrary and then when I try to run the test with nunit3-console.exe .\TestLibrary\TestLibrary.csproj --configfile=.\TestLibrary\app.config it still cannot find the connection strings. Doesn't matter what path I define (relative to nunit, relative to the test library, absolute), always the same.

What am I doing wrong?

Roemer avatar Mar 09 '22 16:03 Roemer

I suspect that the error may be in the VS Project Loader extension rather than the console or engine. To find out, please try running the test assembly directly, rather than the .csproj file.

CharliePoole avatar Mar 09 '22 20:03 CharliePoole

I tried with using the dll instead of the csproj (.\TestLibrary\bin\Debug\net5.0\TestLibrary.dll) but with the same result, the config seems not to be loaded.

Roemer avatar Mar 11 '22 07:03 Roemer

probably this should help http://charliepoole.org/technical/how-nunit-finds-config-files.html

pakinvadim avatar Dec 19 '22 12:12 pakinvadim

we're stuck on this as well. after migrating our tests project from net48 to net6.0 tests that access ConfigurationManager are being directed to C:\BuildAgent\tools\NUnit.Console.3.16.2\bin\agents\net6.0\nunit-agent.dll.config for some reason, previously they would read the file from the executing assembly's directory. explicitly specifying the config file with the configfile setting (which we weren't setting before) doesn't seem to have any effect.

gfody avatar Mar 09 '23 00:03 gfody

I have the same issue, is there any workaround for it?

This problem arise when we need to access the ConfigurationManager.AppSettings, and the ConfigurationManager config path is set to the runner path. When running in VS with resharper, this get set to ReSharperTestRunner.dll.config. When running with dotnet test, this get set to testhost.dll.config. I can work around this by copying App.Config to these two name under the output project.

Im not sure if i should copy the same to nunit's agent folder, as this is a separate folder.

On top of this, since my project use cake to run against a list of test dlls: eg. tool.Nunit3( test1.dll, test2.dll )

Theoretically, even I copy test1.dll to feed to the test agent, it might not be correct for running test2.dll also....? Even worst is, nunit-agent.dll.config itself exists already. Does it mean i need to merge it with my App.Config?

nickkfwong avatar Apr 28 '23 08:04 nickkfwong