Philippe Truche’s Blog

11 March 2011

Unit Testing – A Curriculum

Filed under: .NET, Testing — Tags: , , , , , — Philippe Truche @ 3:36

The subject of unit testing is one that comes over and over in my professional experience. I have been asked many times to teach developers how to unit test. It seems like the words “unit testing” somehow got some level of fame and everyone wants to claim that they are doing it. But to do it well and to do it consistently seems elusive. Worse yet, there tends to be a dichotomy between development managers and the developers about what unit testing really is and why we unit test in the first place.

When asked to put a webinar together, I decided to break it down into 3 separate classes. My first one is called Unit Testing 101 and covers the fundamentals of unit testing. Though it focuses on concepts primarily, it also shows a basic unit test so as to get a flavor. I then created the second course: Unit Testing 201 – Intermediate Unit Testing. In this course, I look at techniques for handling dependencies and introduce basic concepts of test doubles and mocking frameworks. Finally, I reserved the most advanced techniques for Unit Testing 301 – Advanced Unit Testing: I cover topics on compiler techniques in Visual Studio to access members that aren’t public, how to address dependencies without necessarily resorting to using an IOC container, techniques for faking out the HttpContext, employing last-resort frameworks like Microsoft’s Moles to stub out System.DateTime for example, how to manipulate the configuration file, how to host WCF in process (I know, this is bordering on integration tests clip_image001), and a basic overview of Microsoft Pex’s framework.

Yes, it sounds like there is a lot to know to write good unit tests. In fact, just like anything else – practice makes perfect.

In my next post, I will go through the contents of Unit Testing 101.



  1. Great, I’m thinking off how to teach unit testing to people as well. I agree on your 101 and 201 descriptions. However, isnt the 301 course not a bit like going around bad design choices? Ie, reading private fields is not what you want i think. Also faking httpContext or datetime is even doable in the 201 course. I do h ave to say I’m a Java guy, so I do not know .Net’s limits or whatsoever, however I do believe there are always better things. I look forward to your 101 blog post.

    Comment by stefanhendriks — 21 March 2011 @ 4:13

    • Thanks for your comments. About the 301 course – I do teach how to test members whose scope is not public because I have found in my own testing that I needed to do that to perform a more discrete test or series of tests, in accordance with the single responsibility purpose.

      The main difference between the 201 and the 301 is that the 201 covers DI – that in itself seems to be enough of a hurdle for some of the developers. That’s why I keep mocking frameworks for the 301. I also keep the faking out of the System.DateTime for 301 because I show how it can be done with the Microsoft’s Moles framework.

      There is definitely opportunity for restructuring – my main challenge has been keeping to 1 hour for each course 🙂

      Comment by Philippe Truche — 21 March 2011 @ 8:29

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: