Skip to content

sf105/tdd-as-if-you-meant-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test-Driven Development as if you meant it

An exercise for pushing Test-Driven Development to its limits.

Originally by Keith Braithwaite.

https://github.com/sf105/tdd-as-if-you-meant-it

Test-Driven Development isn't complicated

  1. Add a little test
  2. Run all the tests and watch the new one fail
  3. Make a little change
  4. Run all the tests and watch the new one pass
  5. Refactor to remove duplication
  6. Repeat until done


But we observe many people doing "Pseudo-TDD"


Let's turn it up to eleven

  • This exercise turns up the TDD design constraints to full volume
  • It's intended to show how unexpected designs can emerge from the process
  • It's an exercise, it's not intended for everyday use
  • It's suprisingly hard to get started


TDD is about detailed feedback on design choices

  • Thinking about solutions is not getting feedback
  • Feedback comes from tests

Therefore:

Run tests early

  • No, much earlier than that

Run tests often

  • No, much more often than that

In TDD, design thinking happens during refactoring

"Improving the design of existing code"

Existing code that you know works


The exercise

Write code that, given a series of Tic-Tac-Toe[1] moves, describes the state of the game.

1] Also known as "Noughts-and-crosses"


Rules of the exercise

  • Write one new test: The smallest you can think of that seems to point in the direction of a solution.
  • Watch it fail
  • Make the test pass by writing the least implementation code you can in the test method
  • Refactor as required. To create new structure that's not test code, apply these steps very strictly.
    • methods:
      • (preferred) Extract Method to create a new method in the test class
      • (if necessary) Move code into an existing method
    • types:
      • create classes only to provide a destination for Move Method.
      • Populate classes by moving definitions from tests, not the other way round.
  • The person not typing makes sure that these rules are being followed exactly.

Version control

  • check in on every green bar
  • describe your current design thinking in the comment

Discussion

  • How did that feel?
  • What is your code like?
  • Any lessons learned?

Remember, this is just an exercise


There's a sample solution the candidate-solution branch of this repository

About

An exercise for pushing Test-Driven Development to its limits. Originally by Keith Braithwaite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages