Ever since v2.5 there has been a group of tests that fail and which passed in previous versions. Today I ran down the issue.
My project uses the NancyFX framework. NancyFX supports dependency injection which is fortunate because it allowed me to resolve this NCrunch issue.
In NancyFX locating assets is generally done by asking Nancy for the root path of the application. While all tests run fine in the Visual Studio test runner, there was a group of tests that would not run in NCrunch. I resolved the issue as follows:
using System;
using System.IO;
using Nancy;
namespace PortalTests.Modules
{
public class TestRootPathProvider : IRootPathProvider
{
public string GetRootPath()
{
#if NCRUNCH
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..");
#else
var path = AppDomain.CurrentDomain.BaseDirectory;
#endif
return path;
}
}
}
I then inject the TestRootPathProvider into my tests.
Why does the Visual Studio Test Runner work differently than NCrunch in this aspect?
Can you confirm which test framework you're using? I know that in some situations, the AppDomain base directory is inconsistent between MSTest and NCrunch. This is because of the way MSTest handles its 'deployment item' sandboxing, which is different between versions of MSTest and also dependent upon the MSTest configuration file.
I'm using the built-in testing framework in Visual Studio 2015 with its standard test runner. Not using a third party test runner like Resharper or NUnit.
From the command line:
mstest /?
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0