简体   繁体   中英

Error finding configuration file when using nunit3-console runner

I'm trying to execute my SpecFlow tests through nunit3-console runner but I'm receiving the following error:

System.IO.FileNotFoundException : The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was 'C:\Users\...\.nuget\packages\nunit.consolerunner\3.15.0\tools\agents\net6.0\appsettings.json'.

Obviously the runner tries to find the configuration file in the nunit3-console package directory instead of the active/current directory where the file has been copied. Is there any way to specify the correct file directory?

The command I used is the following (or see the image below):

[nunit3-console runner package path] [test .dll path] --trace=off

Maybe it's visible but the nunit3-console runner package I'm using is version 3.15.0 and the version of the framework is .net 6.

Here is the detailed error:

堆栈跟踪

Update :

The problem turned out to be the way the configuration was built.

Before:

Configuration = new ConfigurationBuilder()
    .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .Build();

After:

Configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .Build();

And the difference between those two looks like that:

AppDomain.CurrentDomain.BaseDirectory

"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0\\"

Directory.GetCurrentDirectory()

"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM