[英]Error finding configuration file when using nunit3-console runner
我正在嘗試通過 nunit3-console runner 執行我的 SpecFlow 測試,但我收到以下錯誤:
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'.
顯然,runner 試圖在 nunit3-console package 目錄而不是復制文件的活動/當前目錄中查找配置文件。 有沒有辦法指定正確的文件目錄?
我使用的命令如下(或見下圖):
[nunit3-console runner package path] [test .dll path] --trace=off
也許它是可見的,但我使用的 nunit3-console runner package 是版本 3.15.0,框架的版本是 .net 6。
這是詳細的錯誤:
更新:
問題出在構建配置的方式上。
前:
Configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
后:
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
這兩者之間的區別如下所示:
AppDomain.CurrentDomain.BaseDirectory
"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0\\"
目錄.GetCurrentDirectory()
"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.