Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Unit testing resources

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!

like image 398
Mohit Deshpande Avatar asked Mar 13 '10 19:03

Mohit Deshpande


5 Answers

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.

like image 68
jason Avatar answered Sep 22 '22 00:09

jason


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:

  • 'Getting Started with Pex' video

  • 'Getting Start with Moles' video

like image 41
Dean Kuga Avatar answered Sep 23 '22 00:09

Dean Kuga


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.

like image 28
Mikael Svenson Avatar answered Sep 24 '22 00:09

Mikael Svenson


For mock objects another interesting library is Moq. It has some nice features, especially if you will test lambda expression and all the LINQ stuff (it has some support for that).

As for unit testing I use NUnit but strongly recommend reading Introduction to Test Driven Design (TDD).

like image 34
luckyluke Avatar answered Sep 23 '22 00:09

luckyluke


What, no love for MbUnit?

like image 26
brian Avatar answered Sep 24 '22 00:09

brian