views:

1510

answers:

8

Which do you prefer?

What are the advantages and disadvantages of each for Unit Testing?

EDIT: I will admit that Team System offers a lot more than just Unit Testing, such as performance and load testing of applications and databases. This question was centering around writing unit tests and which do you prefer.

+5  A: 

One very specific reason, is that NUnit won't tie you to the professional edition of the visual studio.

Update: Here is a link about unit testing support on Professional edition in vs 2008: http://msdn.microsoft.com/en-us/library/bb385902.aspx

eglasius
You mean Team System edition of Visual Studio.
eduncan911
@Eric no, I meant exactly that, check the link in my update to the answer
eglasius
+7  A: 

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

Mikelangelo
Running NUnit tests with Resharper or TestDriven.net is also completely integrated in VS, with tests running in a test window etc etc.
Joel in Gö
TestDriven intergration is too weak though I'd prefer something like testmatrix. Also Resharper is great as well.
dr. evil
Yeah, I looked into TestDriven. But, it's $$$.
eduncan911
In vs2008 its unfair to compare with team system only based on unit testing (as that is a small piece of what you get). Specially considering you do have unit tests in the professional edition in vs 2008.
eglasius
+2  A: 

When using MS Tests, you can use CHESS:

CHESS is a tool for systematically testing multithreaded code. Given a concurrent test, CHESS systematically drives the test along all possible thread interleavings.

Also, I found a nice comparison here that claims MS Tests are a little slower than NUnit, but I didn't check it myself.

Ron Klein
I'm looking at CHESS now for some sync testing, but all our unit tests here on Stack Overflow are in NUnit; I guess the threading tests must be with MSTest.
Jarrod Dixon
+4  A: 

One other advantage of NUnit is that it doesn't require that you add anything to your test classes. MSTest requires the presence of a TestContext property. We started out with MSTest but converted to NUnit. I also find NUnit to be significantly faster and I prefer ReSharper's test runner UI.

Jamie Ide
@Jamie you can leave the testcontext out if you want i.e. this would run: [TestClass] public class UnitTest3 { [TestMethod] public void TestMethod1() { Assert.AreEqual(2, 2); } }
eglasius
+1  A: 

Doesn't Visual Studio 2008 allow you to use other testing frameworks when you create the test project? I vaguely remember this from watching the old MVC Framework videos back when Hanselman was doing the preview 2 or 3 videos.

This would allow you to use any testing framework you like and still be able to use it in your VS2008 IDE.

Tacoman667
+4  A: 

Currently NUnit has test categories that allow you to run unit tests separately from slower integration tests.

MS Tests has no such built-in mechanism.

total
@total you can run all tests in the current context, which means: a single test, a class or a whole namespace. With appropiate namespace you can do it.
eglasius
Sorry, I meant from a TFS Build or the MSTest command line. To do something equivalent you would have to specify individual tests or manually create a list of tests in a vsmdi file.
total
+1  A: 

What about testing private methods. Team System create automatically shadow accessors using reflections - does NUnit same?

Maciej
A: 

There is always tools like ReSharper and TestDriven.NET. They will let you run tests from Visual Studio

Denis