際際滷

際際滷Share a Scribd company logo
Im a TDD cheat
and Im not afraid to admit it

Daniel Irvine
@d_ir

6 Sept 2019
SoCraTes Day
Berlin 2019
Im a TDD cheat - @d_ir
Hello, Im Daniel (he/him)
 Independent software
consultant

 Generalist / polyglot. Currently
doing Ruby on Rails for Idean

 I care a lot about quality,
people, TDD

 I organise Queer Code
London

 I wrote this book >
Im a TDD cheat - @d_ir
Strict TDD
You are following strict TDD if you write
100% of your code strictly in
accordance with the rules of TDD.
Im a TDD cheat - @d_ir
Shortcuts and cheats
A TDD shortcut is any coding shortcut
to the TDD process that, once applied,
makes the codebase and tests appear
just as they would if strict TDD had
been applied.

A cheat is a shortcut that has some
element of risk to it. Which makes it fun.
Im a TDD cheat - @d_ir
A. Skip triangulation
Instead of requiring two (or more) tests to start
using a parameter value, just skip the 鍖rst
hardcoded implementation and move directly to
the right implementation.
Im a TDD cheat - @d_ir
B. Skip running your test on red
You know its going to fail*, so why bother?

*misplaced con鍖dence / arrogance
Im a TDD cheat - @d_ir
C. Duplicate a group of tests
A group of tests de鍖ne the behaviour of a system
component.

You need to create another component with the
same behaviour, so you duplicate all the tests as a
batch, rather than follow the TDD cycle for each
test individually.
Im a TDD cheat - @d_ir
D. Premature abstraction
A group of tests de鍖ne the behaviour of a system
component.

Rather than duplicate the tests, you abstract the
functionality even though you dont yet have two,
three or more instances of the component.
Im a TDD cheat - @d_ir
E. Pending tests only
Youre building out a new feature but youre very
unsure of the design.

Instead of writing out each test, you write out only
the description of the test and work as if you had
written the full test.
Im a TDD cheat - @d_ir
F. Spike 鍖rst, test after
Spike the code (write it without TDD, without
tests).

Once youve achieved your desired design, before
committing the code, you write the tests after and
then pretend to the rest of your team that you used
TDD.
Im a TDD cheat - @d_ir
G. Delayed refactoring
Remember that pesky refactor step of the TDD
cycle?

Skip it, and promise yourself that youll do it
eventually, maybe after youve 鍖nished the feature.
Im a TDD cheat - @d_ir
H. Premature refactoring
You are implementing a new module that you
know will follow a similar structure to something
youve written before.

Rather than doing the simplest thing, you skip to
the desired outcome.

Example: you add a before block before you have
a second test.
Im a TDD cheat - @d_ir
Group discussion
Split into twos/threes. Take one of the cheats just
described and answer the following questions.

 Have you done this?

 Is it a shortcut or a cheat?

 What are the risks?

 Does it point to a smell?

 Is there a better way?
Im a TDD cheat - @d_ir
Whats your work鍖ow?
TDD is a work鍖ow. Is it okay to modify it to suit your needs?

Of course it is. If youre working on a team, then be courteous by
letting people know what youre modifying and why.

We have to 鍖nd ways to bring moments of joy and fun into our
professional lives. Programming can be terribly boring if you let it
be.

Kent Beck has recently done this with TCR. Its a variant of TDD
that has sparked people imagination, and got people excited about
TDD again. Isnt that a wonderful thing? TCR is the inverse of a
cheatits adding new constraints rather than relaxing existing
constraints.
Im a TDD cheat - @d_ir
Theres no shame in cheating
Worth repeating: theres no shame in cheating!
In fact there is an advantage to being a TDD cheat.
Being a self-confessed cheat brings humility to your identity.
TDD practitioners can come across as unapproachable / pretty
anal. People can be afraid to work with TDD practitioners because
theyre afraid of the judgement.
Non-TDDists sometimes feel fear when working with TDDists. They
believe that they arent good enough, or they are being judged.
Bringing some humility to your workby saying sure, I cheat
is no bad thing.
Im a TDD cheat - @d_ir
Final thoughts
Rules are made to be broken.

(The rules are still necessary for us to bring
novices along with us.)
Its important to have fun, just like Kent Beck did
with TCR.

Its important to remain humble.
Im a TDD cheat - @d_ir
Want to learn more? Buy my book please #noshame
Available on Amazon or on
packtpub.com.

496 pages of sheer goodness,
teaching TDD from the ground up.

It covers shortcuts, cheating and
much more.

Or get in contact:

Email daniel@conciselycrafted.com
Twitter @d_ir

More Related Content

I'm a TDD cheat and I'm not afraid to admit it

  • 1. Im a TDD cheat and Im not afraid to admit it Daniel Irvine @d_ir 6 Sept 2019 SoCraTes Day Berlin 2019
  • 2. Im a TDD cheat - @d_ir Hello, Im Daniel (he/him) Independent software consultant Generalist / polyglot. Currently doing Ruby on Rails for Idean I care a lot about quality, people, TDD I organise Queer Code London I wrote this book >
  • 3. Im a TDD cheat - @d_ir Strict TDD You are following strict TDD if you write 100% of your code strictly in accordance with the rules of TDD.
  • 4. Im a TDD cheat - @d_ir Shortcuts and cheats A TDD shortcut is any coding shortcut to the TDD process that, once applied, makes the codebase and tests appear just as they would if strict TDD had been applied. A cheat is a shortcut that has some element of risk to it. Which makes it fun.
  • 5. Im a TDD cheat - @d_ir A. Skip triangulation Instead of requiring two (or more) tests to start using a parameter value, just skip the 鍖rst hardcoded implementation and move directly to the right implementation.
  • 6. Im a TDD cheat - @d_ir B. Skip running your test on red You know its going to fail*, so why bother? *misplaced con鍖dence / arrogance
  • 7. Im a TDD cheat - @d_ir C. Duplicate a group of tests A group of tests de鍖ne the behaviour of a system component. You need to create another component with the same behaviour, so you duplicate all the tests as a batch, rather than follow the TDD cycle for each test individually.
  • 8. Im a TDD cheat - @d_ir D. Premature abstraction A group of tests de鍖ne the behaviour of a system component. Rather than duplicate the tests, you abstract the functionality even though you dont yet have two, three or more instances of the component.
  • 9. Im a TDD cheat - @d_ir E. Pending tests only Youre building out a new feature but youre very unsure of the design. Instead of writing out each test, you write out only the description of the test and work as if you had written the full test.
  • 10. Im a TDD cheat - @d_ir F. Spike 鍖rst, test after Spike the code (write it without TDD, without tests). Once youve achieved your desired design, before committing the code, you write the tests after and then pretend to the rest of your team that you used TDD.
  • 11. Im a TDD cheat - @d_ir G. Delayed refactoring Remember that pesky refactor step of the TDD cycle? Skip it, and promise yourself that youll do it eventually, maybe after youve 鍖nished the feature.
  • 12. Im a TDD cheat - @d_ir H. Premature refactoring You are implementing a new module that you know will follow a similar structure to something youve written before. Rather than doing the simplest thing, you skip to the desired outcome. Example: you add a before block before you have a second test.
  • 13. Im a TDD cheat - @d_ir Group discussion Split into twos/threes. Take one of the cheats just described and answer the following questions. Have you done this? Is it a shortcut or a cheat? What are the risks? Does it point to a smell? Is there a better way?
  • 14. Im a TDD cheat - @d_ir Whats your work鍖ow? TDD is a work鍖ow. Is it okay to modify it to suit your needs? Of course it is. If youre working on a team, then be courteous by letting people know what youre modifying and why. We have to 鍖nd ways to bring moments of joy and fun into our professional lives. Programming can be terribly boring if you let it be. Kent Beck has recently done this with TCR. Its a variant of TDD that has sparked people imagination, and got people excited about TDD again. Isnt that a wonderful thing? TCR is the inverse of a cheatits adding new constraints rather than relaxing existing constraints.
  • 15. Im a TDD cheat - @d_ir Theres no shame in cheating Worth repeating: theres no shame in cheating! In fact there is an advantage to being a TDD cheat. Being a self-confessed cheat brings humility to your identity. TDD practitioners can come across as unapproachable / pretty anal. People can be afraid to work with TDD practitioners because theyre afraid of the judgement. Non-TDDists sometimes feel fear when working with TDDists. They believe that they arent good enough, or they are being judged. Bringing some humility to your workby saying sure, I cheat is no bad thing.
  • 16. Im a TDD cheat - @d_ir Final thoughts Rules are made to be broken. (The rules are still necessary for us to bring novices along with us.) Its important to have fun, just like Kent Beck did with TCR. Its important to remain humble.
  • 17. Im a TDD cheat - @d_ir Want to learn more? Buy my book please #noshame Available on Amazon or on packtpub.com. 496 pages of sheer goodness, teaching TDD from the ground up. It covers shortcuts, cheating and much more. Or get in contact: Email daniel@conciselycrafted.com Twitter @d_ir