views:

1426

answers:

10

I am coming from Java and am currently working on a C# project. What is the recommended way to go about a) unit testing existing C# code and b) accomplishing TDD for C# development?

Also is there an equivalent to EMMA / EclEmma (free yet powerful code coverage tool) for Visual Studio and C# code?

+14  A: 

1 Nunit
2 NCover or
3 PartCover (I never used it)

Jacek Szymański
NCover is not free, unfortunately :(
NM
+2  A: 

NUnit would be it.

Adam Haile
+7  A: 

NUnit is patterned after JUnit, but if you're using Visual Studio 2008 then consider the built-in unit testing framework.

C. Lawrence Wenham
Apparently, the first NUnit was simply the Junit source run through CSC to see what would compile. They went through the minimal conversions necessary.
chris
I use the built-in testing framework, but also install TestDriven.Net to get the nice right-click menu extensions that allow me to run individual tests and suites easily.
tvanfosson
+2  A: 

NUnit, but NCover is only part of the answer as it isn't free. I've asked elsewhere about that.

Keith
+2  A: 

VS2008 Professional has the Team System unit testing functionality baked in.

Darcy Casselman
+2  A: 

NUnit for sure.

Chad Moran
+2  A: 

Unit test framework: NUnit

Unit test runner: Various, but personally I like the one in ReSharper. (ReSharper costs money, but is easily worth it for the various productivity improvements.)

Coverage: NCover (I think this used to be free, but it now costs money. Hmm.)

Jon Skeet
+1  A: 

I'd install:

  1. NUnit for your Unit testing framework http://www.nunit.org/index.php
  2. Test driven.net for runing your tests http://www.testdriven.net/
  3. Rhino Mocks as your mockign framework http://ayende.com/projects/rhino-mocks.aspx

As and aside I find it odd that the NUnit guys seem to be using php to host their homepage...

Omar Kooheji
+3  A: 

I would highly recommend Gallio (formally mbUnit) for unit testing, and (unfortunately not free) NCover for code coverage.

Oliver Hallam
+2  A: 

Regarding your question about unit test frameworks:

NUnit 1.0 was a direct port of JUnit. NUnit 2.0 moved away from JUnit syntax in order to take advantage of the .NET platform. xUnit.net is a newer unit test framework (from Jim Newkirk - one of the NUnit 2.0 developers - and Brad Wilson) that states as a goal exposing "advances in other unit test library implementations that have not really surfaced in .NET," which I read as "keeping up with JUnit."

Alan Ridlehoover