Skip to main content

Using xUnit.Net with .Net 4.0

I’ve been using xUnit.Net for a while now. It’s just a tiny bit cleaner and slightly less abrasive than other .Net unit testing frameworks. Leaving out unnecessary stuff like [TestFixture] and shortening Assert.AreEqual to the equally clear but shorter Assert.Equal don’t seem like big improvements but when you type them several times a day tiny improvements start to add up. I also like the use of the [Fact] attribute instead of [Test]. It shifts the focus from testing to defining behavior. So how do we get all this goodness working with the Visual Studio 2010 beta?

Creating tests is as easy as it normally is, you can just reference xunit.dll it in your 4.0 test-projects. Running your 4.0 tests can be a problem, the testrunners included in the package are compiled against the 2.0 framework so they won’t load 4.0 test-assemblies.

The obvious solution is to just download the source and compile it yourself. (+1 for open source!) Make sure you select the .Net Framework 4 and not the .Net Framework 4 Client profile in the project properties for the console runner because it uses some logging functionality that’s not available in the client profile. Everything will just run after this.

I found an easier solution on Mark Needhams blog In his article xUnit.NET: Running tests written in Visual Studio 2010 he explains how you can run the 2.0 console runner with the 4.0 clr by adding a section to the .config file instead of recompiling the whole thing. Adding the following lines to the xunit.console.exe.config should do the trick;

   1: <configuration>
   2: ...
   3:     <startup>
   4:         <requiredRuntime version="v4.0.20506" safemode="true"/>
   5:     </startup>
   6: ...
   7: </configuration>


I found the same trick works with the gui runner too. Unlike the console runner it doesn’t come with a config file so you need to create one yourself, add the <startup> section and it will load 4.0 test-assemblies.


When you want better VS.Net integration there are some other testrunners you can use. The easiest here is good old TestDriven.Net. You can download the version 3 beta for Visual Studio 2010 integration and run your 4.0 tests with it.


Another testrunner that works is the one included with Resharper. Normally it isn’t free but Jetbrains has released a public beta for version 5 that works with Visual Studio 2010. To get xUnit.Net working with Resharper you need the xUnit.Net contrib project. The maintainers have done a great job keeping it up to date with Resharper 5.0 alpha and beta builds so they’ve got a version for the latest beta available.


Popular posts from this blog

Square One available on the Android market

This is just a short post to let you know that a first version of the Android app I’ve been working on for the last couple of weeks is available on the Android market . The app is called Square One and it’s a simple bassline synthesizer. It’s free so try it out and let me know what you think of it, but be prepared it’s still an early version. I hope to add more features in the next few months and maybe build something that can be used to create real music. The lower part of the screen contains the sequencer controls that can be used to program your own bass lines. On the left is a four by four grid of buttons where you can select a step in the sequence. On the right you can select the note to be played on that step. When you’re done you can press Start and the sequence starts playing. The knobs on the top can be used to control a couple of parameters from the synthesizer engine that creates the sound. You can control the cutoff frequency and resonance of the low-pass filter, attack an

Android development resource links

I've been playing with the Android SDK and I have a growing list of bookmarks to Android dev resources for my own use. I thought the best place to keep them would be here on my blog. That way other people can benefit too. I'll keep updating this list so feel free to add suggestions in the comments.

Acer Iconia A500 review

A couple of weeks ago I bought an Android tablet, the Acer Iconia A500. Today I received an email from Acer asking to fill in a short survey to tell them what I like and don't like about my new tablet. I might as well share my thoughts on this tablet in a short review on my blog.