views:

185

answers:

4

Hi,

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?

+1  A: 

ASP.Net MVC doesn't make any specific demands of a framework, any will work just fine. NUnit is the most widely used, and for that reason it is my default choice.

Once you get into unit testing, some of the other frameworks offer different advanced features that you may like to check out.

I don't know anyone using the MS unit testing framework.

James L
+1  A: 

I would recommend to start from xUnit if your have not used any testing framework before. It's hard to decide which framework is better but I think that xUnit is the "most modern" among NUnit, MbUnit and MSTest. Start learning xUnit from this article and then this

eu-ge-ne
+1  A: 

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.)

jrista
Does anyone have a feature comparison of xUnit to the latest version of nUnit 2.5 Beta?
Todd Smith
+1  A: 

I am using MSTest :) so now you know one ;)

Seriously, I think that MSTest is a the best framework for the start with TDD. It is liteweight and it is generating all that you need for the wrapup and the most important thing, it is integrated in the visual studio...so, why don't you start with mstest and later on you can switch to advanced frameworks with no problems.

So in short, I would recomend a MSTest.

cheers

Marko