2020.2 integration tests fail under resharper using asp.net core 3.1 and WebApplicationFactory
A few of our components do the following in CreateHostBuilder:
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var appConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
.Build();
When we point WebApplicationFactory to use this host builder, it works fine in resharper 2020.1.4, works fine in any other test runner (visual studio, nunit console etc) but with resharper 2020.2 we get:
----> System.IO.FileNotFoundException : The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\username\AppData\Local\Temp\ReSharperTestRunner_wpfotagm\1lnwgvwr\appsettings.json'.
Also if we are using WebApplicationFactory and CreateWebHostBuilder, we are seeing a different error:
System.InvalidOperationException : Solution root could not be located using application root C:\Users\username\AppData\Local\Temp\ReSharperTestRunner_ns02afzi\zgdgcnz0.
at Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(IWebHostBuilder builder, String solutionRelativePath, String applicationBasePath, String solutionName)
Again this is working in resharper 2020.1.4 and works with visual studio test runner and nunit console runner.
Is this a known regression? Anyone else getting similar errors?
Please sign in to leave a comment.
Hello Andrew,
Please try to change the following setting ReSharper | Options | Tools | Unit Testing | Test Frameworks | NUnit | NUnit 3 | "When running tests set Environment.CurrentDirectory to" to "Test assembly's folder"
VS 2019 Pro here, just upgraded R# last week to 2020.2 "built on 2020-08-10," when I started getting this error:
OneTimeSetUp: System.ArgumentException : The directory name 'C:\Users\steve\AppData\Local\Temp\ReSharperTestRunner_hlmhfnoj\bjxyhvb3\Configuration\' does not exist.
Parameter name: path
Exception doesn't have a stacktrace
Following Andrey's instructions above fixed my issue.
You can get around this by setting the ASPNETCORE_ENVIRONMENT variable in ReSharper | Options | Tools | Unit Testing | Test Runner Environment Variables section.