0
votes

I'm using VS 2013 and NUnit. I'm running my tests in Resharpers's TestRunner GUI - this thing:enter image description here

I have multiple projects (Solution.Foo, Solution.Bar, etc), and tests for each project in Solution.Foo.Tests, Solution.Bar.Tests, etc.

One of my tests in Foo.Tests is accessing a file, located in the Solution.Foo.Tests Folder.

I use TestContext.CurrentContext.TestDirectory to locate it and when I run that test it all works just fine. If I run the whole suite of tests in Foo.Tests, (i.e. click on Solution.Foo.Tests in the Runner GUI and run) then it's fine. But if I select one test from Bar.Tests and my file-reading test from Foo.Tests, then it fails, because suddenly TestDirectory is set to a path in Bar.Tests.

It's as if NUnit set TestDirectory once when it starts running a collection of tests, determined by where the first test is and then never updates it again.

Any ideas what's going on and how to fix it?

1

1 Answers

3
votes

ReSharper has an optimisation for speed, by sharing an AppDomain across multiple assemblies. The downside to this is that it will pick an arbitrary assembly to be the main one, which means the directory can be wrong (and it might not pick up the correct app.config, too).

You can disable the optimisation in ReSharper → Options → Unit Testing, by checking the "Use separate AppDomain for each assembly with tests".