I started playing with .NET 4.0 and Visual Studio 2010 over the weekend. I quickly came to an interesting problem however. I switched a while ago on .NET 3.5 to using xUnit.NET instead of NUnit or the unit testing in Visual Studio 2008. I like to redistribute my test suites with my products as a support aid for end-users that are using my applications. Since I can’t redistribute the Visual Studio testing assemblies, I prefer the open source frameworks. But the problem that I quickly discovered was that neither xUnit.NET or NUnit supported .NET 4.0 yet, which is completely understandable. I figured out a couple of configuration changes that could be applied though to get unit tests to work and run in the .NET 4.0 runtime.
Both xUnit.NET and NUnit have application configuration files for their respective test runners. The first thing that you need to do is tell the standard CLR host to load the test runners using the .NET 4.0 CLR runtime. This can be done by adding a element to the configuration file:
This will cause both NUnit and xUnit.NET to use the .NET 4.0 CLR instead of the .NET 2.0 CLR.
I further discovered that NUnit had some problems loading the nunit.core.dll assembly from the lib private subdirectory. I was able to get around this problem by adding the following fragment to the element in the configuration file for NUnit’s test runners:
After making these changes, I had no issues running my test suites with either NUnit or xUnit.NET.