Preamble
I know, that this question seems to have anwsers here:
I have nearly the same problem like ReSharper 10 test runner failing to find AppSettings referenced from external file. But these answer stated, that the problem should be gone with ReSharper 10.0.2
Question
I included a custom.xml
files with custom settings, and I need to read them from my unit test. But my file is not found.
I looked, where the process runs, and included this line
var curdir = Directory.GetCurrentDirectory();
So I found out, that curdir
is C:\\Users\\MYUSER\\AppData\\Local\\JetBrains\\Installations\\ReSharperPlatformVs11_000
Now it is obvious that my file cannot be found. After googling it, it found the above mentioned questions. But none of these solutions works for me.
These are my settings:
Visual Studio Configuration
Microsoft Visual Studio Ultimate 2012
Version 11.0.61219.00 Update 5
Microsoft .NET Framework
Version 4.6.01038
Installierte Version: Ultimate
Right click on the project or solution in the VS solution-explorer and choose 'Run Unit Tests' Or go to the Resharper menu, choose Unit-Testing and choose one of the options from there.
ReSharper adds the Unit Test Explorer window to Visual Studio (ReSharper | Unit Tests | Unit Tests or ReSharper | Windows | Unit Tests, or Ctrl+Alt+U ). Using this window, you can explore and run or debug unit tests of all supported frameworks in the entire solution.
You don't list any version of NUnit installed, but you tagged this 'nunit' so I'm going to make an assumption you are using it! Further, I'm assuming NUnit >= 3.0... ignore this if otherwise. :-)
NUnit 3.0 stopped changing current directory. It's a bad idea for us to do that anyway and it's a really bad idea with 3.0, when multiple assemblies in differing directories may be running at the same time.
So, assuming still it's an NUnit problem, instead of using a relative path, use TestContext.CurrentContext.TestDirectory as the location of your file.
try this:
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With