Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit vs. Visual Studio 2008's test projects for unit testing [closed]

People also ask

Is NUnit still used?

The latest version of NUnit is NUnit3 that is rewritten with many new features and has support for a wide range of . NET platforms. NUnit has been downloaded more than 126 million times from NuGet.org.

What is difference between NUnit and MsTest?

MsTest is a native unit testing library that comes with Visual Studio from Microsoft. NUnit is an extra Nuget package that needs to be installed on top and interact with the APIs of Visual Studio. Nunit likely doesn't have direct integration into the native APIs like MsTest does.

What is the best testing framework for C#?

xUnit test is the best Unit testing framework for . Net programming languages like C#, VB.Net, and F#. xUnit derives its structure and functionality from SUnit of Smalltalk.

Is NUnit a unit testing tool?

NUnit is an open-source unit testing framework for the . NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.


Daok named all the pro's of Visual Studio 2008 test projects. Here are the pro's of NUnit.

  • NUnit has a mocking framework.
  • NUnit can be run outside of the IDE. This can be useful if you want to run tests on a non-Microsoft build server, like CruiseControl.NET.
  • NUnit has more versions coming out than visual studio. You don't have to wait years for a new version. And you don't have to install a new version of the IDE to get new features.
  • There are extensions being developed for NUnit, like row-tests, etc.
  • Visual Studio tests take a long time to start up for some reason. This is better in Visual Studio 2008, but it is still too slow for my taste. Quickly running a test to see if you didn't break something can take too long. NUnit with something like Testdriven.Net to run tests from the IDE is actually much faster. Especially when running single tests. According to Kjetil Klaussen, this is caused by the Visual Studio testrunner. Running MSTest tests in TestDriven.Net makes MSTest performance comparable to NUnit.

The unit-testing framework doesn't actually matter much, because you can convert test classes with separate project files and conditional compilation (like this, Visual Studio → NUnit):

 #if !NUNIT
  using Microsoft.VisualStudio.TestTools.UnitTesting;
 #else
  using NUnit.Framework;
  using TestClass = NUnit.Framework.TestFixtureAttribute;
  using TestMethod = NUnit.Framework.TestAttribute;
  using TestInitialize = NUnit.Framework.SetUpAttribute;
  using TestCleanup = NUnit.Framework.TearDownAttribute;
  using TestContext = System.String;
  using DeploymentItem = NUnit.Framework.DescriptionAttribute;
 #endif

The TestDriven.Net plugin is nice and not very expensive... With only plain Visual Studio 2008 you have to find the test from your test class or test list. With TestDriven.Net you can run your test directly from the class that you are testing. After all, unit tests should be easy to maintain and near the developer.


Benefits/changes of the Visual Studio 2008 built-in unit testing framework:

  1. The 2008 version now is available in professional editions (before it required expensive versions of Visual Studio, and this is just for developer unit testing) that left a lot of developers with the only choice of open/external testing frameworks.
  2. Built-in API supported by a single company.
  3. Use the same tools to to run and create tests (you may run them using the command line also MSTest).
  4. Simple design (granted without a mock framework, but this is a great starting point for many programmers).
  5. Long term support granted (I still remember what happened to NDoc, and I don't want to commit to a testing framework that might not be supported in five years, but I still consider NUnit a great framework).
  6. If using Team Foundation Server as your backend, you can create work items or bugs with the failed test data in a simple fashion.

I have been using NUnit for two years. All is fine, but I have to say that the unit testing system in Visual Studio is pretty nice, because it's inside the GUI and can more easily do a test for private function without having to mess around.

Also, the unit testing of Visual Studio lets you do covering and other stuff that NUnit alone can't do.