ASP.NET MVC Unit Test

asp.net-mvcunit testing

I'd like to try unit test in ASP.NET MVC framework. But I don't know which unit test framework I have to choose.

NUnit, xUnit.net, MbUnit. or the unit test framework included with Visual Studio, which one is better?

Best Answer

If you are interested in following BDD guidelines, I highly recommend xUnit.NET with Moq as the mocking framework. The two are some of the most forward looking and modern unit testing frameworks available these days, and combined they make both a powerful and flexible unit testing platform. xUnit.NET is extremely extensible as its Fact and Trait attributes can be extended with your own attributes, and the testing frameworks behavior can be changed to suit your needs.

A great example of this flexibility is the ObservationAttribute and supporting framework to allow BDD style testing with xunit.net, found here:

http://iridescence.no/post/Extending-xUnit-with-a-Custom-ObservationAttribute-for-BDD-Style-Testing.aspx

I use the above BDD-style testing to create Test-Class-Per-Unit style BDD tests for my ASP.NET MVC controllers (well, and everything else I unit test, too.)