NUnit vs Visual Studio 2008's Test Projects for Unit Testing?

I am going to be starting up a new project at work and want to get into unit testing. We will be using VS 2008, C#, and the ASP.NET MVC stuff. I am looking at using either NUnit or the built in test projects that VS2008 has, but I am open to researching other suggestions. Is one system better than the other or perhaps easier to use/understand than the other? I am looking to get this project set up as kind of the "best practice" for our development efforts going forward.

Thanks for any help and suggestions!!


Daok named all the pro's of VS2008 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 MS build server like CC.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 2008 but 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.
    Accorting 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, VS->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 VS2008 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 test should be easy to maintain and near the developer.


    Benefits/changes of VS2008 Built-in Unit Testing Framework

  • The 2008 version now is available in professional editions (before it required expensive versions of VS, this is just for developer unit testing.) that left a lot of developers with the only choice of open/external testing frameworks.
  • Built in API supported by single company.
  • Use the same tools to to run and create tests (you may run them using the command line also MSTest)
  • Simple design (granted no Mock framework, but this is a great starting point for many programmers)
  • Long term support granted (I still remember what happened to nDoc, I don't want to commit to a testing framework that might not be supported in 5 years, but I still consider nUnit a great framework.)
  • If using team foundation server as your backend, you can create work items or bugs with the failed test data in a simple fashion.
  • 链接地址: http://www.djcxy.com/p/28030.html

    上一篇: 我如何使用Assert来验证是否抛出异常?

    下一篇: NUnit vs Visual Studio 2008的单元测试测试项目?