I have a C# test project compiling under .NET6, using System.Configuration.ConfigurationManager 7.0.0 (so I can use configuration files instead of JSON files, for legacy reasons).
The code looks like this:
[Test]
public void TestConfiguration()
{
var filePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
Console.Error.WriteLine($"Configuration filepath is {filePath}");
var testValue = ConfigurationManager.AppSettings["TestValue"];
Assert.IsTrue(testValue == "testing");
}
My .nUnit file (mytest.nunit) looks like this:
<NUnitProject>
<Config name="Debug" binpathtype="Auto" runtimeFramework="6.0" configfile="./mytest.config">
<assembly path="PrimeService.Tests\bin\Debug\net6.0\PrimeService.Tests.dll" />
</Config>
</NUnitProject>
My .config file (mytest.config) looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="testValue" value="testing"/>
</appSettings>
</configuration>
Directory structure looks like this:
D:\src2\csharp\coretest\
- mytest.nunit
- mytest.config
D:\src2\csharp\coretest\nUnit
D:\src2\csharp\coretest\PrimeService.Tests
And finally, my command line and results look like this:
D:\src2\csharp\coretest>nunit\console\nunit3-console.exe mytest.nunit --configfile=mytest.config
NUnit Console 3.16.1 (Release)
Copyright (c) 2022 Charlie Poole, Rob Prouse
Wednesday, January 18, 2023 5:04:08 PM
Runtime Environment
OS Version: Microsoft Windows NT 6.2.9200.0
Runtime: .NET Framework CLR v4.0.30319.42000
Test Files
mytest.nunit
Configuration filepath is D:\src2\csharp\coretest\nunit\console\agents\net6.0\nunit-agent.dll.config
[ ... rest of output removed for brevity ...]
Note that the actual configuration file being used is not what is specified.
This may be related to https://github.com/nunit/nunit-project-loader/issues/44 but that was years ago and I'm running the latest release.
Note: I used --trace=Verbose, but nothing in the log files mentioned how it's obtaining the config filename.
Does someone know something I don't to get this to recognize my configuration file? The same configuration using the same body of code for .NET Framework 4.8 works as expected.