views:

296

answers:

7

I migrated from Java to C# and so I am wondering how to unit tests in C#. I remember using JUnit to test my Java applications. How can I unit test in C#? What are some good resources for unit testing in C# USING THE DEFAULT UNIT TESTING LIBRARY? I don't really need a port. A good resource would be like a nice PDF file, article, or better yet, a video!

+11  A: 

NUnit is effectively an idiomatic port of JUnit to the .NET land. There is also a unit testing framework built into Visual Studio, but since you're familiar with JUnit and NUnit is free, that would be my recommendation.

For mocking and stubbing, I like Rhino Mocks.

Finally, Roy Osherove, has a nice book The Art of Unit Testing which is a nice discussion of unit testing in general, but will also point you to other tools and resources.

Jason
+1 for Roy's book. It's not a very big book (as in many pages), but it's very well written. This book, combined with some experience on existing projects, got me up to speed on testing.
Erik van Brakel
NUnit and JUnit are both ports of SUnit for Smalltalk. +1 for Rhino Mocks.
BlueRaja - Danny Pflughoeft
Yep, Roy's book is outstanding.
Steven
So is Roy's blog - http://weblogs.asp.net/rosherove/. The new TypeMock Test Lint should be particularly useful if one is a newbie to unit testing. I particularly recommend one of Roy's screencasts where he critiques others' unit testing code - you learn a lot very quickly that way: http://weblogs.asp.net/rosherove/archive/tags/TestReview/default.aspx
Pat
A: 

Try out NUnit .YOu can also look at the Unit test projects in VS 2008 or VS 2010.

ydobonmai
+2  A: 

I like using MSTest since it's bundled with Visual Studio (most versions).

Also check out NUnit and xUnit.

For test runner I like using ReSharper.

Mikael Svenson
+1  A: 

What, no love for MbUnit?

brian
+1  A: 

For mock objects another interesting library is moq. It has some nice features esp. if You will test lambas and all the linq stuff (it has some support for that).

As for unit testing I use nUnit but strongly recommend reading this

luckyluke
+1 for Moq. I find it far more intuitive than Rhino Mocks. http://code.google.com/p/moq/
TrueWill
+4  A: 

You didn't mention what version of VS are you using but if it is VS 2010 RC give Pex and Moles Visual Studio 2010 Powertools a try...

"Pex automatically generates test suites with high code coverage. Right from the Visual Studio code editor, Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications."

"Moles allows to replace any .NET method with a delegate. Moles supports unit testing by providing isolation by way of detours and stubs. The Moles framework is provided with Pex, or can be installed by itself as a Microsoft Visual Studio add-in."

Videos:

kzen
A: 

+1 for NUnit + Rhino Mocks + Resharper :)

Sapphire