Monday, March 19, 2007

Running unit tests in Visual Studio Express

The brilliant can't run in Visual Studio Express (well, from what I've heard, it can, but Microsoft asked for it to be removed).

Therefore, to run unit tests in Visual Studio Express, you must set your debugger application to point to NUnit.exe (or the brilliant MBUnit).  This isn't straightforward in Express and means editing the .csproj file by hand and telling it to run the NUnit exe.

Today, I wanted to run and debug some unit tests I'd written in the XNA Game Studio Express (Visual Studio Express with some XNA bits bolted on).  I couldn't have the excellent right click/run unit test feature and I thought there's got to be a better way than editing the .csproj file manually.

So I changed the unit test project to be a console application and added this to the Main method.

public static void Main( )
@"C:\Program Files\NUnit-Net-2.0 2.2.9\bin\NUnit-console.exe",
new string[ ] { Assembly.GetExecutingAssembly( ).Location } );

And it worked.  Which was nice.


Jamie recently left a message saying that the new Beta version DOES support Express editions!  Read his post here and get downloading straight away!


Jamie said...
This comment has been removed by the author.
Jamie said...

You should find it works again now: