Question

Would anyone recommend me a unit testing framework for MVC ? There are a lot of choices which gets me confusing which framework to choose.

NUnit or XUnit.Net or MSTest ??

Thanks, Venkat

Was it helpful?

Solution 2

I agree-all three are good. It maybe not to the point but it's much harder to find good Mocking Framework,because it's not easy to mock DbContext class (especially when You use Sql Server). If You use it i can recommend TypeMock,otherwise RhinoMocks will be good.

OTHER TIPS

I would only advice not to use MSTest.

In my current project we were using MSTest for about a year. I've been using NUnit for years but other people were new to unit testing so to keep it simpler for them (not bring 3rd party testing frameworks with it's runners) we used MSTest with it's integration in VS. It was PITA!

With MSTEST you have to keep a list of all your tests for VS. You have to maintain this list (add/remove new/removed tests). Tests disappear from this list and you can't say why. File that keeps this list doesn't merge! So when you add new tests at the same time another person adds tests you have conflict that you have to resolve. I don't get why. It should merge with no problem.

You can also look for some reasons why not use MSTEST.

Why I'm migrating from MSTest to xUnit.net by Mark Seemann

I'd recommend xUnit. It's a very modern unit test framework that is very simple and concise. The feature I love most about xUnit is that they have a single object instance per test method, which means you are far less likely to have tests influence each other. NUnit e.g. does not have this feature, which could easily lead to flaky tests. Furthermore, xUnit uses standard .NET functionality to do things like setup and teardown. It does this through constructors and destructors, so you don't have to learn new conventions but can just use your own. Lastly, xUnit test classes look far nicer IMHO due to less attributes being used and the assertion methods being shorter.

All three which you mention are very solid and will get the job done. Personally, I prefer MSTest. It's simple to learn and use yet it has decent functionality. Just like xUnit it can also Setup [TestInitialize] and Clean [TestCleanup] on pre-execution and post-execution of a test. My suggestion would be to take one and learn it. Once you get to know it and learn its strengths and weaknesses you can move on to another one that can help you get the job done faster and/or better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top