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:
Code:
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?