Outline for TDD Tutorial in C#
Overall Theme: Implementing the PanMedia retail system with TDD Technology: C#
TO DO
Zhon:
- Check Student Hardware
- Gather Zhon's stories
- Hudson CI: Add code coverage (If time)
- Backup plan (Written instructions?) in case VM doesn't work
Finalize VM image and test it (Zhon & Kay)
Kay:
- Prepare Mocking Kata Slides
- Prepare Fitnesse Demo
- Prepare Rhino Mocks 3.5 Cheat Sheet (if time)
Jeff:
- Prepare Refactor Demo
- Prepare "naming, dependencies and encapsulation" lecture or demo
Richard:
- Prepare GUI Kata Slides
- Prepare demo of refactoring GUI code (Mediator/Humble Object)
Course Schedule
Day 1 (Kay, Jeff and Richard at lunch time)
Theme of the day: "The Big Picture: The basic rhythms of driving code development down through acceptance and unit level tests".
Skills you will practice:
- Planning techniques
- Designing declarative acceptance tests
- Fitnesse
- Unit Testing with NUnit
- Test-driven development
Zhon Introductions & setup - 30 Min
Done Prime Factors Kata - 30 Min
- Develop code in a test-driven way that will detect prime numbers, starting very simply and entering a rhythm
Zhon Release Planning - 45 Mins
Overview Product Goals for PanMedia
- Create User Stories
- Estimate Stories
- Pick stories for first iteration (Please pick: Selling items decreases inventory)
Kay Interactively define test cases for "Selling Items" story - 30 Mins
Kay Show: Implement Fitnesse test page and fixture for test cases - 30 Mins
Zhon Iteration planning, task breakdown & group sign-up to implement user stories - 15 Mins
- Selling items decreases inventory
Lunch
Jeff Show code written TDD style with Driver, Navigator, Questioner, and Commentator (Jeff, Kay, Zhon, Richard) - 30 Mins
Class Pass off first story - 2 Hours
- Use the acceptance test developed during live demo - or write an acceptance test
- Write unit-tested code to support acceptance test
- Rinse, lather repeat until story is complete
- Pass off story with a show and tell
Zhon Daily Debrief - 30 Mins
Day 2 (Jeff)
Theme of the day: "Keeping it Clean: Performing common refactors as a part of everyday coding".
Skills you will practice:
- Removing duplication
- Triangulation
- Extracting methods/classes
- Correct naming
- Increasing encapsulation
- Removing dependencies
- Single responsibility principle (SRP)
Kay Mocking Kata - 30 min
- Demonstrate London style mocking.
Zhon Iteration planning, tasking, and signup - 15 minutes
- Add a new media type (Books) (This guides them to a big refactor)
- Or
- (Easier) Put categorized items shopping "bag" and put items into it for checkout
- (Medium) Put results from a search into the same "shopping bag" for checkout
- (Harder) Given a "bag" of items, check out by totaling price, applying discounts and verifying credit card
Jeff Walk through refactor of existing code to remove duplication and triangulation - 30 mins
Class Work on stories - 1 hour 45 mins
- Lunch -
??? Walk through naming, dependencies and encapsulation - 30 mins
Class Implement and pass off stories - 2 Hours
- Finish acceptance tests, unit tested code
- Pass off story with a show and tell
Zhon Daily Debrief - 30 Min
Day 3: (Richard)
Theme of the day: "Testing the Untestable: Using mocking and separation of concerns to preserve testability".
Skills you will practice: Two styles of mocking, mocking tools, humble object pattern
Richard Kata - Add GUI to prime factors - 30 Min
Zhon - Iteration planning, tasking, and signup - 15 Min
- GUI stories
(Easier) Talking to a (non-existent, mock) web service to veryify CCN using exp. date & CVV/CVC #
- (Medium) Based on previous purchases (for any user) offer recommendations on popular items
(Harder) Search for a title based on any available field in the database, sort & highlight field
??? Mocking tools available - 30 min
Class Work on stories - 1 Hour 45 Min
- Lunch -
Richard Demonstration of how to separate concerns in C# GUI code and make business logic testable - 30 min
Class Implement and pass off stories - 1 Hour
- Finish acceptance tests, unit tested code
- Pass off story with a show and tell
??? - Review release plan for coming "iterations", recommend stories, prioritize, etc. - 15 min
If time permits - Richard - Live refactor of their code - 30 Min
Zhon - Daily Retrospective - 30 Min
Zhon - Closing remarks - 15 Min
Technical Starting Point
Participants will be provided an (approximately 7Gb) Sun VirtualBox 3 image and expected to install and run it on any machine (Mac, PC, Linux) with 2Gb or more of RAM and 10 Gb free disk space.
- The disk image will contain all development tools and utilities necessary for the course, as well as example code representing the first few "user stories" of the project having already been implemented using test-driven development.
- Browse Catalog:
- The user can choose which catalog to browse: Books or Music. They then see all the items in that catalog (in no particular order). The Book catalog only contains books; the Music catalog only containes music.
- Books have the following fields: Title, Author, Publish Date, Publisher, Format, ISBN, UPC.
- Music has the following fields: Title, Artist, Release Date, Label, Format, UPC
- All fields are strings.
- There is no validation. An item with all null fields is valid.
- There is no check for duplicates.
A PanMedia admin specifies the UPC number of the item, and the item's cost (to PanMedia), the MSRP (manufacturer's suggested retail price), and the current discount.
- An item's discounted price (MSRP minus discount) is shown when a user browses the catalog.
The user supplies a credit card number (number only - no expiration date, etc). The system responds with whether the digits constitute a potentially valid credit card number. This is done very simply using check digits, according to the LUHN formula http://www.beachnet.com/~hstiles/cardtype.html
- Browse Catalog:
(Not too much setup, and maybe run them through the steps we had to take to set up)
Outline for TDD Tutorial for Agile Roots
Test Driven Development/Refactoring Tutorial (3 hours)
Goal: Try TDD again (and again).
Handout: Page containing tools, books, and web resources to start your learning.
Introduction
TDD in Action Simple steps to clean code. (Java)
Demo: Creating a bowling game scorer in Java using IntelliJ
TDD Together
Follow-along exercise: Prime number generator step by step
TDD pairing in groups of four
Exercise: Password Validator
Reflection
Break
Refactoring legacy code Making code testable; making good code great. (C#)
Demo: Extracting methods to test UI Events in C# using Resharper (25 minutes)
Refactor Your Code
Exercise: Add Password recommender to the Password validator
Where do we go from here?
- Tools
- Resources
- Where to start studying
Debrief / Q & A
Reflection
- Share your parting takeaways
Results from the Salt Lake Agile Round Table question: When did you realize you had become test infected?
- When tests caught a bug, everyone had had missed.
- A four month project finished without any bugs.
- Reading Michael Feathers' book: Working Effectively with Legacy Code
- When I could start a project without fear or stress
- Lots of accidental practice like in The Karate Kid
- To prove to the TA that my code worked
- When I saw a trainer work through examples
- Worked on a contract with such bad code I had to write tests
- Just tried it and found I loved it
- When I had tests passing but knew there was a bug—I realize, I need to write my tests first.
- I knew I was infected when I felt guilty when I didn't write my tests.
