How Do We Teach TDD?Considering the Dreyfus Model of Learning C. Keith Ray Coach, Trainer, Developer at Industrial Logic, Inc. firstname.lastname@example.org twitter: @ckeithray http://industriallogic.com
Whats TDD?TDD is Test-Driven Development. The simpledescription of TDD is:Red-Green-Refactor-Repeat: write a test thatfails (red), write just enough code to make it pass(green), then refactor to a good design (aka"simple code"), and repeat.
Dreyfus ModelDreyfus came up with a model of learning. Henamed ﬁve levels: Novice Advanced Beginner Competent Proﬁcient ExpertSee http://en.wikipedia.org/wiki/Dreyfus_model_of_skill_acquisition
NoviceCompletely new to the thing to be learned.Wants recipes, rules, constraintsThey dont know what "good" look likes yet, sothey want fast feedback.Craves rules.
Advanced beginnerKnows the rules, but not all the contexts forthem, knows just enough to be "dangerous."As a software developer, probably writing "bigballs of mud".Better to have them learning in a safeenvironment to learn from their mistakes. 5
CompetentCan do a task without needing instructions.Identiﬁes patterns and uses them, mostly inappropriate contexts.May be oﬀended if you treat them like a Noviceor Advanced Beginner.
ProﬁcientGood, but now trying to become expert.Lots of experience / practice.Knows how to do stuﬀ, but cant tell people howto do it.(Teaching has its own Novice to Expert levels)
ExpertBeyond rules.Working on instinct.Needs to compare notes with other experts.Arguing about their subject reﬁnes theirunderstanding of it.
TDD seems so simple, so why is it hard to teach?Teacher: its red, green, refactor, repeat.<long time later>Student: ok, heres all my tests!Teacher: wheres the code?Student: I havent written it yet. Teacher: Photo by striatic
TDD seems so simple, so why is it hard to teach?Teacher: its red, green, refactor, repeat.<long time later>Student: heres my ﬁrst test. [400 lines of codein a single test.] Photo by Marcin Wichary
TDD seems so simple, so why is it hard to teach?Teacher: its red, green, refactor, repeat.Student: <Doesnt understand why the testshould fail before it is made to pass, so writescode and tests so that the tests usually pass theﬁrst time they are run.> oops
TDD seems so simple, so why is it hard to teach?Teacher: its red, green, refactor, repeat.Student: heres my tests and code.Teacher: nice, but youve got a very large class, with avery large method, and allyour tests are repeating lotsof code. Did you refactor?Student: I thought wedrefactor next month!
TDD seems so simple, so why is it hard to teach?Because each of the steps of TDD require skillsin three main areas:Writing tests.Writing simple code.Refactoring.
Theres more, Refactoring Requires:Recognizing symptoms of baddesign (code smells).Making small transformations toimprove the design. (The actualRefactorings.)Recognizing good design (aka"Simple Code")
"Simple Design"Kent Becks rules for simple design were: 1. Runs all the tests. 2.No duplication. 3. Expresses the developers intentions. 4.Minimizes the number of classes and methods. Photo by GN
Getting back to Dreyfus...We teach using web-base materials in livetraining and via coaching.Our web-based materials assume the student isin the Novice stage of learning about TDD.We also assume the student is at least in theCompetent stage as a programmer.We encourage pairing of students — it makes alarge improvement in learning.
What Novices WantA "novice" is completely new to asubject.They want rules, recipes,formulas, step-by-stephow-to-do-it.They dont know enough tojudge their own results, sothey need fast, frequentfeedback by coach or trainer. Photo by Steve Snodgrass
Breaking TDDSkill-Sets into Novice-sized Pieces
Demo VideoVideos are usually short (around 5 minutes) and demonstrate a technique or make a point.
Demo Quizzes We have a variety of quiz types. Students cancomment on quiz answers or post questions and get a prompt response from Industrial Logic staﬀ.
Demo: Exercises TDDing Big Bills Billing SystemTask 1: Calculate A Simple Phone BillTask 2: Calculate Excess MinutesTask 3: etc.Student writes the code, compares it withsolution(s).Almost all solutions are demonstrated invideo form and downloadable code.
Demo: Critiques Your score was 62% based on our Automated Critique. This ranks you as Intermediate.A Graph of Your TDD Activity See several examples here.
ConclusionOur web-based training with critiques providesfeedback that Novices and Advanced Beginnersneed, and which would otherwise require one-to-onecoaching. This works for our live training as well aspurely web-based training.Try it out: http://elearning.industriallogic.com(PS: Competent, Proﬁcient, and TDD Experts should try Sessions.)See also Dan North appling the Dreyfus model to a more general level of"best practices": http://www.infoq.com/articles/better-best-practices
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.