Unit-testing – How does NUnit for C# compare with Unit Test facility integrated with Visual Studio

comparisonnunittddunit testingvisual studio

I need to work in a team to develop a mid scale Desktop application developed using C# .NET. Prior to this, I have not applied Unit Testing and Test Driven Development. I am aware that there exists many tools and framework for Unit Testing C# applications. As of now, I am aware of Nunit and the Unit Testing facility integrated with Visual Studio.

I would like to know, how do the two compare?

Best Answer

There is some overlap between the two for sure. NUnit is the predecessor, and as a result more mature. C# Unit Test framework is younger, but integrated with Visual Studio.

I've come from the Java world where JUnit is king (there are others, but none as popular), and NUnit 2.5.x is a really good match to the way JUnit 4 works. In fact, it works much better than the Java counterpart.

As far as test definition is concerned, I favor NUnit. Sure MS Test has similar (but different) attributes that you apply to your classes, but I believe it is lacking some features that can save you some work on some types of testing. You may want to check out a similar discussion on StackOverflow.

I like the new assertion model built in to NUnit (it is using the Hamcrest style asserts) because they are both easy to read and easily extensible.

  • NUnit will have better 3rd party support, MS Test will have better integration (out of the box).
  • NUnit will have better flexibility and extensibility, MS Test will suffer in this area.
  • Both run unit tests and check your results, both will work for TDD.
Related Topic