Nunit VS. Visual Studio 2008's Test Projects for Unit Testing

Unit test, NUnit or Visual studio?

NUnit has few advantages over MS-Test

  1. Suite attribute - can aggregate tests and execute them separately (useful for large projects with fast and slow tests for example)
  2. Readable Assert method, e.g. Assert.AreEqual(expected, actual) vs Assert.That(actual, Is.EqualTo(expected))
  3. NUnit has frequent version updates - MS-Test has only one per VS version.
  4. Many integrated runners including Resharper and TestDriven.NET
  5. Expected exception message assertion - can be done using attribute in NUnit but must be done using Try-Catch in MS-Test
  6. [TestCase]! NUnit allows for parameter-ized tests.

Are there real differences between NUnit and Microsoft's Unit Testing Framework (VS 2008)?

Roy Osherove just wrote a recent blog post summarizing the differences between NUnit and MSTest. I think it answers your question.

He concludes that NUnit wins for Unit Testing, but MsTest has much better abilities for integration based testing and team testing with Team System.

Visual Studio 2008 unit tests and nunit

Try modifying the file C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\1033\SimpleUnitTest.zip\SimpleUnitTest.cs (after making a backup, of course). Keep a copy of your updated version elsewhere as this may get overwritten by updates.

FWIW -- I found this by searching for the string using Microsoft.VisualStudio.TestTools.UnitTesting; inside files starting at the top level directory of the VS application directory.

How to Integrate NUnit With VS 2008

Check out TestDriven.NET, a free Visual Studio add-in that allows you to run your unit tests with NUnit directly from the IDE.

Which Unit Test framework should I start with for C# in Visual Studio 2008? (Windows Forms app)

If it just a simple application, the MSTest framework built into VS2008 should tick all the boxes. It is not the same as NUnit, though a lot of people (mistakenly) refer to it as if they were the same thing.

I have never used it for mocking, so maybe someone else can elaborate on that. It generates a separate project in your solution that is just for the purpose of testing. This is a good explanation of how to use it.

alt text

(source: geekzone.co.nz)

Edit:
Doing a bit more digging, I came across this comparison of MSTest and NUnit.

Drawbacks of NUnit Framework:

  • Installation of NUnit comes in a separate MSI.
  • No Integration with Visual Studio.
  • Requires writing test cases manually.
  • No auto generation of code.
  • Requires opening separate window (NUnit Console or GUI) to execute test cases.
  • Ordering of test cases execution not available.
  • No inbuilt feature to debug test cases.
  • No inbuilt feature to enable/disable test cases.
  • No inbuilt feature to give additional information of test cases like stack trace, Trace Information etc.
  • No inbuilt feature to sort test cases based on Computer Name, Class Name and Host Type etc.

That's from the comparison article I linked to.

I have never used NUnit, only MSTest for C# and JUnit for Java, so I am kind of biased in that respect. MSTest has always worked really well for me for WinForms, with features like being able to run the tests individually, show really detailed reports (with individual trace logs) and autogenerate all the boilerplate test code and do all those kind of things that make VS2008 such a brilliant IDE. By the sounds of it, NUnit has worked well for others and they have their reasons why they like it.

Unless you have a particular reason to take the NUnit/Testdriven.NET approach, like you need a certain feature, or you just prefer that way of setting up tests and trying to integrate it back into VS, then I don't see any reason not to just use MSTest which works right out of the box.

NUnit vs Team System Unit Test

Nunit:

Advantages:

  • Free
  • Very similar to team system in attributs and methods for assertion, some names are even the same

Disadvantages:

  • Tests must be run via console or external application ( this can be seen as an advantage, but not from my point of view).

Team System testing

Advantages:

  • A part of VS, you can run tests in a test window.
  • If you run a team system server you can run tests more easily as a part of the automated build

Disadvantages:

  • Expensive
  • Still isn't as stable as NUnit

A comparison between team system and Nunit

We use team system 2008 as we are gold certified partners to microsoft, but earlier used Nunit due to bug related issues in VS 2005. I prefer the VS solution.

Both are good solutions for your work, look also out for other free solutions like:

Good alternatives to Team System

What are the differences between Microsoft TestTools' UnitTesting and NUnit?

See Migrating from NUnit to MSTest.

As to why you might try convincing your team to migrate the other way, see NUnit vs. MsTest: NUnit wins for Unit Testing.

How can I run Test projects with Visual Studio 2008 Standard Edition?

Try Gallio as explained best in this blog post by Richard Dingwall, and for Visual Studio support, use TestDriven.Net to runs it.

There's some information available in this Google Groups post as well.


From Gallio's website:

At present Gallio can run tests from MbUnit versions 2 and 3, MSTest, NBehave, NUnit, xUnit.Net, and csUnit. Gallio provides tool support and integration with CCNet, MSBuild, NAnt, NCover, Pex, Powershell, Resharper, TestDriven.Net, TypeMock, and Visual Studio Team System.

Unit testing in Visual Studio 2008 Standard

I am using NUnit with Visual Studio 2008. In the past I
have also used it with Visual Studio 2005.

It works great.

For running it I use a project where the unit tests are
defined, separate from the main project. For interactive use
I then set this project to the default project (right-click
on project/Set as Startup Project) and set
Properties/Debug/"Start external program" in this project to
something like

C:\Program Files\NUnit\bin\nunit-x86.exe

In the same screen "Start Options/Command line arguments" is
set to something like

..\..\..\temp2\MSQlib1,2008-03-14a.nunit"\MSQlib1,2008-03-14a.nunit

This points to the NUnit project file
("MSQlib1,2008-03-14a.nunit" in this example)- the ".."s are
due to being relative to the bin\Debug folder where the DLL
for the project is located (the application is this case is
the NUnit GUI application) and which will be the current
directory when debugging is started.

The result is that the NUnit GUI application is started when
F5 is pressed in Visual Studio and calls back into the
application when the unit tests are run from the NUnit GUI application.

This allows breakpoints to be set in the unit tests (if
needed).
E.g. to get information on why a unit test failed by doing
inspection with the debugger. In my case this has sometimes
been necessary when the mass of elements carbon, hydrogen,
nitrogen, oxygen and sulphur were changed slightly and
masses of amino acids no longer were within limits.



Related Topics



Leave a reply



Submit