I’ve been working on a unit testing paper that sums up my experience in unit testing, and discusses some of the core information that I feel is important about the subject. It’s very much a work in progress, but I wanted to get it out sooner rather than later. I’ll be continuously updating it as time goes on.
Update: I updated the PDF location to one that doesn’t require registration.
There are some really great books out there about unit testing, but I think some of them are trying too hard to be long enough to be considered a “book”. I set out to create a document that fills the gap between the various snippets of information from blog posts, and the comprehensive books on the subject. If you’re interested in something a bit more in-depth, here are some great books on the subject:
The paper currently consists of 5 main sections:
- Why Write Unit Tests?
- Unit Test Mechanics
- Common Unit Testing Strategies
- Designing for Testability
- Advanced Techniques
Here is a more complete snapshot of the current outline:
- Introduction
- Unit Testing & Managers
- What Unit Tests Really Do
- Types of Testing
- Testing Framework
- Test Runner
- Unit Test Structure
- Other Test Attributes
- What is Refactoring?
- Test Driven Development
- Evolving Code
- When Should You Write Unit Tests?
- Test is for Functionality, Not Code!
- The Constraints of Reality
- Interfaces – Quick Overview
- Using a Mocking Framework
- Stubs
- The Test Driven Design Paradox
- Testing Under Pressure
- Extracting Duplicate Logic
- Modular Design Benefits
So what are you waiting for? Go check it out online instantly, you can even download it as a PDF if you like. Is anything missing? Is anything just plain wrong? I’d love to hear your feedback.
Remember, if you want to hear more about unit testing, I’ll be speaking in Northeast Wisconsin Saturday, May 9th.


I really like your paper. I’m fairly inexperienced with unit testing and it’s really helped to clarify things for me, especially the part about mock objects.
Cheers
A really good paper !
You should talk about data-oriented unit tests i.e. MbUnit’s RowTest, etc… All unit test frameworks support this kind of testing. Once you’re there, you should take a look at Pex (http://research.microsoft.com/pex) which should give an idea where automated unit testing might be headed.
Keep on the good work,
Peli
On the 19th slide, there’s an example using the CompareTo method of IComparable, requiring it to return 1 for bigger, -1 for smaller; any other value if they are the same.
Looking at the documentation of the method, I’ve checked that it works like this
Less than zero (not strictly -1) => smaller
Zero (strictly zero) => equal
Greater than zero (not strictly 1) => bigger
Check the table at http://msdn.microsoft.com/en-us/library/system.icomparable.compareto(VS.71).aspx
Just a minor contribution. Still reading the paper, and liking what I read so far.
Another point in slide 19:
“Programming the class against the interfaces is elegant for number of reasons. First, as I mentioned, we’re defining the “how” for retrieving the email addresses. (…)”.
IMHO, interfaces define the “what” who implements the interface does, no matter how. The interface implementation defines “how” to do the “what”.
Also, do any of you guys know any mock framework that lets me create partial mock without the need to create interfaces for everything or declaring a method as virtual? It doesn’t seem right to me modifying good code (e.g. creating an unnecessary interface) just to make testing easier.
Thanks in advance
Thank you …
Thank you …
[...] – Practical .NET Unit Testing [...]
Very good paper. Looking forward to read the yet not finished sections.
Good Stuff.
Thank.
Appreciate your time and effort. thank you!
Schöner und motivierender Beitrag. Danke
Schöner und motivierender Beitrag. Danke
Thank you very much!