Rodrigo Guerreiro

"The purpose of a programming system is to make a computer easy to use", in The Mythical Man-Month
posts - 61, comments - 16, trackbacks - 14

ASP.NET MVC RC2 + xUnit + Gallio

In case you didn't notice, ASP.NET MVC RC2 is out. Following that release, I've decided to create a new ASP.NET MVC project, but using xUnit instead of MSTest for the test framework. I also want this change to have no impact in the way I develop, which means that I want the unit tests to run inside Visual Studio 2008.

 

Why xUnit?

Here's why.

 

Introducing Gallio

From Gallio homepage:

The Gallio Automation Platform is an open, extensible, and neutral system for .NET that provides a common object model, runtime services and tools (such as test runners) that may be leveraged by any number of test frameworks.

The Gallio platform seeks to facilitate the creation of a rich ecosystem of interoperable testing tools produced by and for the community at large so as to address a far wider range of testing needs than any previous independent testing framework has done before. Unit tests, integration tests, performance tests, and even semi-automated test harnesses should all be able to leverage common facilities where appropriate. Moreover, they should present consistent interfaces to the world so that they can easily be integrated into the systems and processes of the enterprise.

At present Gallio can run tests from MbUnit versions 2 and 3, MSTest, NBehave, NUnit, xUnit.Net, and csUnit.  Gallio provides tool support and integration with CCNet, MSBuild, NAnt, NCover, Pex, Powershell, Resharper, TestDriven.Net, TypeMock, and Visual Studio Team System.

 

Combining all together

DISCLAIMER: The following steps are provided "as is" without any warranty or support. Use this under your own responsibility. Also, this only works in Visual Studio 2008 Team System and I'm assuming that you already have the ASP.NET MVC RC2 installed (but I assume that this also works with RC1 but I haven't test it).

 

1. Download xUnit (xunit-1.1.zip) and Gallio latest releases.

2. Unzip the xUnit file and run the xunit.installer.exe. In the ASP.NET MVC section click on the Enable button (case it's enabled which in this case you'll need to do nothing) and you'll get the green result, like in the picture below.

image  image

3. Execute the downloaded GallioBundle-3.0.5.546-Setup-x86.msi installer and follow the instructions.

4. Create a new ASP.NET MVC project.  When the below screen appears you're now able to choose the xUnit as the test framework. Click OK.

image 

5. Now the tricky part. Unload the test project (right-click on the project and choose the Unload project option).

6. Right-click on the unloaded project and choose Edit...csproj and you'll get something like this:

 image

7. Right below the image element paste this.

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>  
8. Save and reload the project.
9. Build the solution. Probably you'll get the errors below (if not go to step 10). This happens because the xUnit project templates are built for the ASP.NET MVC RC1 and we're using the ASP.NET MVC RC2. Simply add references in the test project to the assembly System.Web.Routing and System.Web.Abstractions. See the release notes in case you're interested knowing what changed. Basically, this assemblies are no longer distributed with the MVC installer because are already shipped with .NET Framework 3.5 SP1.
image
10. Build again the solution and hopefully all goes OK.
11. Now go to Test->Windows->Test View. Again, this only works in Visual Studio 2008 Team System. With luck you'll have 9 unit tests.
12. Select all and run. You're now running the tests successfully inside the Visual Studio 2008 with Gallio (Check the icon between the checkbox and the result column).
The two last tests are failing, once again, because are built for the RC1. I'll leave the resolution to you :)
image 
 
Success! Hope this helps someone.
 
Until next time ;)
 
Technorati Tags: , , ,

Print | posted on Wednesday, March 04, 2009 10:35 AM

Powered by: