Reputation: 1190
I am using ConfigurationManager.AppSettings["someKey"]
to retrieve values from app.config
appSettings
<appSettings>
<add key="someKey" value="value" />
...
However, when I use this in my unit tests, the ConfigurationManager.AppSettings
collection is empty.
This happens only when I run the tests from JetBrains Rider
IDE!
Running them from Visual Studio
(even with ReSharper runner) works perfectly fine and values are loaded.
It is a .Net 5 project using XUnit framework.
What is going on with Rider here?
Upvotes: 2
Views: 1100
Reputation: 23
ConfigurationManager.AppSettings["someKey"]
the app.config should be structed this way
<configuration>
<appSettings>
<add key="someKey" value="value" />
</appSettings>
</configuration>
Add the following lines in project file so that it copies the app.config to be findable by the Resharper test runner. VS may be doing this itself, however Rider seems to need it done explicitly
<Target Name="CopyCustomContent" AfterTargets="AfterBuild" \>
<Copy SourceFiles="app.config" DestinationFiles="$(OutDir)/ReSharperTestRunner.dll.config" />
<Target/>
Hope this helps!!
Upvotes: 2