ericschmidt;9690 wrote:
To do some more testing, I ended up rolling back to using NUnit v2.6.4, and found that this issue goes away. Also, in v3.5, tests like this only seem to fail when the tests are being run in parallel. If I rerun a failed test using the "Run selected test in new task runner process" that the test passes. However, if I click the "Run all tests" button at the top of the NCrunch Tests UI, these tests fail. I'm not sure how to further troubleshoot this.
This is definitely a sequence dependent issue then. Either the test code or the code under test is changing the current directory during a run. Because there are tests later in the execution pipeline that depend on the current directory being set consistently, they fail intermittently depending on which tests have been previously executed before them in the test process. See
sequence dependent tests for more information on this kind of failure.
Under NCrunch there are many variables that affect the sequence in which tests are executed. NUnit V2 also has a different internal architecture to NUnit V3, so is likely that this problem will not present itself consistently between different runners or versions of NUnit.
I recommend performing a search of your codebase for anything making a call to Directory.SetCurrentDirectory. Note that the call may not actually be in your code at all (for example, you may be calling into compiled 3rd party code or a Win32 API that changes the current directory).
Creating an
NUnit SetUpFixture with a teardown section that throws an exception if the current directory has been changed is one way to find the test causing the problem if you execute the tests manually independently or in groups.