Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Teaching someone to test using an Isolation Framework

Part of my job at work is to teach and mentor other developers on our team.  Right now I am in the process of teaching two of our developers how to create unit tests (notice I did NOT say integration tests because most anyone can do those).  We are also learning how to create our tests by utilizing an Isolation Framework (aka mocking framework).

I am really excited for this opportunity because I firmly believe that you create better software when you do it by creating tests to prove your code works.  I am also excited because both of the developer buy into the idea of testing and are extremely eager to learn how to to better test their code.

Because we had a few days of downtime because of the Christmas holiday before our 1st sprint on our project we thought it would be a good time to do some pairing (guess it would be better called tri-pairing).  Our plan of attack was to start to flush out some of the features in our system but do it in a total TDD manor.  We were also going to be utilizing the Rhino Mock Isolation framework in our tests.

So over the next 2 days we spent about 12 hours or so working building out our code.  Over this time we actually were able to create an complete end to end 'version' (I say version because we did not fill in all the functionality of the code but were able to get all the major pieces stubbed out) which allowed us to flush out many, many more business requirement and build a simple, yet flexible code base.

I hope both of my co-workers learned a ton from this exercise, I know I did.  This was the first time where I had actually spent any significant amount of time teaching someone who was new to testing how to do so.  Sure I had spent an hour here or an hour there, but nothing like this. 

What I really wanted to share with everyone is what I learned form this experience.

Slowdown, slowdown, slowdown
The first thing you should do when teaching something how to do anything is SLOWDOWN.  You have to remember that if you are talking/teaching to someone who is new to this they have to not only try to process the information so they can understand it, they also have to try to remember it.

Make NO assumptions, teach as if they know nothing
This one was the most important thing I learned.  You cannot make assumptions on anything.  Anytime you say anything make sure you fully explain it.  If you use an acronym EXPLAIN IT.  Any time you mention a buzz word EXPLAIN IT.  Plan and simple EXPLAIN EVERYTHING

Have them drive
During the teaching part it is critical that you have then code, have them tell you what to do.  It is ok for you to 'lead' them in the right direction, but you must not always drive.  This will really help to drive home the concepts.

Provide examples both with and without the Isolation framework
In our case because I was trying to teach them testing using an Isolation framework it really helped when I would create a test (aka integration) with no mocks and then re-create it with mocks.  Doing this really helped to explain to them how using the Isolation framework removed dependencies.

Don't let them skate by
Don't let them simply nod their head as if they understand.  Make sure you keep asking them if there is anything you can clear up or explain better.  At first they are going to simply say no, they are good.  But as you keep asking and start having them drive they WILL start to ask more questions, I promise.

Turn off any coding tools such as ReSharper (or the likes) and do NOT use shortcuts
This may have been the biggest issue for us at first.  I am pretty good with ReSharper (if I can toot my own horn here) and I was coding with it as I would do if I were by myself.  On more than one occasion the would look at me cross-eyed and ask 'what the hell just happened'.  Finally I simply stopped using it for the first day.  On the second day I went back to using R#, but I turned on Keyboard Jedi so they could see what was going on.  Even though I turned on Keyboard Jedi, I tried my best to make sure to explain what just happened when used R#.

Anyway, I have rambled on long enough and I think I have pretty much gotten my thoughts out there.  I really enjoyed working with these guys and I am looking forward to doing so again when we get back from break.

Hope this helps,

Till next time,

Posted 12-30-2008 11:21 AM by Derik Whittaker
Filed under: , , , ,



Casey wrote re: Teaching someone to test using an Isolation Framework
on 12-30-2008 4:48 PM

Never turn off resharper .. The best way to see how powerful it is, is to show it in action in real code

Derik Whittaker wrote re: Teaching someone to test using an Isolation Framework
on 12-30-2008 4:56 PM


I could not disagree more in this case.  The goal was for them to learn testing w/ isolation framework.  Trust me in our case they were spending too much time trying to figure out how to use R# then they were on testing.

There is a time/place to show them how to use R# (or another tool like it) and this was not it.

Dew Drop - December 30, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - December 30, 2008 | Alvin Ashcraft's Morning Dew
on 12-30-2008 6:40 PM

Pingback from  Dew Drop - December 30, 2008 | Alvin Ashcraft's Morning Dew

Reflective Perspective - Chris Alcock » The Morning Brew #254 wrote Reflective Perspective - Chris Alcock » The Morning Brew #254
on 12-31-2008 6:23 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #254

Clinton Begin wrote re: Teaching someone to test using an Isolation Framework
on 01-01-2009 12:46 PM

Well done.  There are some great thoughts in this post.  Cheers.

sarah wrote re: Teaching someone to test using an Isolation Framework
on 01-02-2009 1:50 AM

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to

say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Jeff Gonzalez wrote re: Teaching someone to test using an Isolation Framework
on 01-02-2009 1:46 PM

Great post.  I spend about 1/2 of my time as a trainer, the other half doing code.  

I've taught mocking.  Lots.  I find if I start by showing how IOC and DI are useful, even outside the world of testing, students "get it" better.

Sort of like:

ME: Ok, one of the things this Customer class needs is the ability to send an email to the customer.  Should the customer class know how to send email?

Class (hopefully): No! Separation of Concerns!

ME: So, let's create a class the Customer uses to send email. .... anybody know how to send an email?

Class: silence.

ME: Ok, let's pretend like we do.  We'll create an interface that looks like it knows how to send email.  For now, we'll create a class that pretends to send an email, and tomorrow we'll figure out how to do it for real...

A little contrived - but it works.  We use constructor injection for our "fake" email sender, etc.  

When we move into Mocking and TDD they already understand the "hard" part. ;)

Great tips from you here.  Thanks.

Christopher Bennage wrote re: Teaching someone to test using an Isolation Framework
on 01-02-2009 2:04 PM

Excellent suggestions.

Dave Schinkel wrote re: Teaching someone to test using an Isolation Framework
on 01-04-2009 1:13 PM

Wow, I wish our Lead at Kaplan would have taken your attitude!  Nice post. wrote Teaching someone to test using an Isolation Framework
on 01-04-2009 1:16 PM

You've been kicked (a good thing) - Trackback from

Dave Schinkel wrote re: Teaching someone to test using an Isolation Framework
on 01-04-2009 1:18 PM

However, reading this again.

I don't know what you mean when you said you turned off R#, for them or you?  Why?  If you're used to it, what benefit are you going to have by turning it off from someone who has continually told me to USE IT.

Derik Whittaker wrote re: Teaching someone to test using an Isolation Framework
on 01-04-2009 1:22 PM


my suggestion to turn off R# is because if the people you are teaching has no clue what R# is or how to use it.  You will more then likely provide them with information overload if you it.  By turning it off you allow them to focus on how to create the tests, not how to use R#.

Kjetil Klaussen wrote re: Teaching someone to test using an Isolation Framework
on 01-16-2009 3:21 AM

Great post! You really made some good points in there, and as I work as a consultant I often have to address the problem of implementing TDD in an organization. I often don't find it very hard to convince devs to start writing tests, because the list of advantages of using testing often speaks for itself. What I find hard is, as you point out, to teach them how to write good unit tests and to stay on the righteous path. It is quite a barrier to actually get going and I find that the learning curve often is a bit steep – especially for novice coders. Throwing testing frameworks, TDD test-first mentality, and mocking framework at someone who's not yet comfortable with neither C#, .Net or programming in general, could be just too much to handle. I haven’t thought of R# actually making the understanding even harder, but that is a very valid point and I will keep that in mind next time.

But I have found one method that I think works pretty well when it comes to teaching unit testing. I've blogged about it <href =">, but the essence is to sit down and do some pair-programming. And when doing the pair programming I start out writing the unit test first. This way I show them a bit how the testing framework work, how I structure the tests and often some use of mocking. Unit tests should be simple, so all in all the test should be fairly easy to understand even for junior devs. The worst part to explain is often the mocking, but using easy-to-read mocking frameworks like Moq helps a lot. Then when the test is written (and nothing compiles or passes) I hand over the keyboard to my fellow coder so that (s)he can implement the functionality. I simply tell her/him; "Make it go green!” Then we move on to the next test; I write the test, the 'soon-to-be-test-infected-dev' next to me writes the functionality.

Now, it's important to understand that at this point the dev(s) you are teaching are probably not yet convinced that this is the right way to code. The point where most devs seem to see the (green) light is when a test fails due to some code changes that they never thought would break any functionality. When the test that covers that functionality blows up, that's when you've got yourself a loyal TDD'er on your team. Or that's at least my experience, but as always; your mileage will vary :)

Kjetil Klaussen wrote re: Teaching someone to test using an Isolation Framework
on 01-16-2009 7:49 AM

I had a suspicion that the link wouldn't render correctly... The blog post I meant to refer to was this:

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)