Andy
Andy

Reputation: 2774

Introduction to unit testing for C#

I'm looking for a good introduction/tutorial for unit testing C#. Most tutorials I've come across so far have either been too basic to be useful or too complex for someone new to unit testing.

(Using Visual Studio 2008 Professional for Windows applications)

Upvotes: 3

Views: 511

Answers (4)

P.K
P.K

Reputation: 19157

Read The Art of Unit Testing by Roy Osherove. It is very good. alt text

Upvotes: 4

Dan Bryant
Dan Bryant

Reputation: 27515

It was when I started reading about Moq that I realized unit testing didn't have to be painful. There are some good links near the bottom of the page as to how unit tests can be built with mocking.

One nice thing about using interfaces for controlled coupling and testing is that adding an interface to an existing code base is not a breaking change. I'm adding new features to some legacy code and I've been creating interfaces for existing classes so that the new features can be developed and tested in isolation. It's been working well so far and I plan to continue this style of testing on other projects. For me, the key was to avoid designing complex stub classes with lots of ugly conditional code to expose different cases for my tests. It got to the point where the test code was so complex that I couldn't be sure if it was the code or the test that was broken.

Upvotes: 0

Bruno Costa
Bruno Costa

Reputation: 2720

Perhaps a book? I would recommend you the Pragmatic Unit Testing in C# with NUnit.

It's very complete in my opinion.

Upvotes: 1

David
David

Reputation: 219037

Is it just a specific tool for which you're having trouble finding good tutorials? When I was new to the subject I found the NUnit tutorial to be a good starting point:

http://www.nunit.org/index.php?p=quickStart&r=2.4

Rhino Mocks would be good to learn as well to complement the unit testing framework:

https://stackoverflow.com/questions/185021/rhino-mocks-good-tutorials

Upvotes: 2

Related Questions