Entering in the full TDD, including:
- how TDD works and why it is required in Agile development
- why there are so many people that say that TDD does not work
- how to fix the problems in bad TDD to make it effective
- and the primary value of the sofware: make it adaptable
2. @drpicox
Breaking myths and understanding why
Software Values
The Triangle △ Example
Fixing Code Smells
Discipline
The Rules
TDD is Dead
TDD vs. BDD
Tips for adoption
TEST DRIVEN DEVELOPMENT
5. @drpicox
@drpicox
PRIMARY VALUE
The ability to tolerate and facilitate change
SOFTWARE VALUES
5
TDD — SOFTWARE VALUES
SECONDARY VALUE
The current software meets the current needs of the current user
14. @drpicox
@drpicox
Tests do also suffer from code smells
If a test is fragile, we cannot leverage on them to refactor code
BUT...
14
TDD — FIXING CODE SMELLS
Refactor
TESTS
?
17. @drpicox
@drpicox
Accounting is a discipline that is in charge of
studying, measuring and analyzing the assets
and
f
inancial and economic situation of a
company or organization, in order to facilitate
decision-making within it and external control,
presenting the information , previously
registered, in a systematic and useful way for
the different interested parties.
ACCOUNTING
17
TDD — DISCIPLINE
—Wikipedia
Double-entry bookkeeping
In 70 AD Plinius the Elder described
the structure of the "Tabulae Rationum".
Account Debit Credit
Furniture $1,500
Cash $1,500
$1,500 $1,500
18. @drpicox
@drpicox
1. You are not allowed to write any production
code unless it is to make a failing unit test pass.
2. You are not allowed to write any more of a unit
test than is suf
f
icient to fail; and compilation
failures are failures.
3. You are not allowed to write any more
production code than is suf
f
icient to pass the
one failing unit test.
PROGRAMMING
18
TDD — DISCIPLINE
20. @drpicox
@drpicox
It is a discipline of programming
about coding
about testing
and about design
(in the form of refactoring)
WHAT IS TDD?
20
TDD — THE RULES
21. @drpicox
@drpicox
The steps are the following:
write a “single” test describing an aspect of the program
run the test, which should fail because the program lacks that feature
write “just enough” code, the simplest possible, to make the test pass
“refactor” the code until it conforms to the simplicity criteria
repeat, “accumulating” unit tests over time
HOW FOLLOW THE RULES?
21
TDD — THE RULES
Write a Test
✘ Test Fails
✔ Test Passes
Write the Code
✔ Test Passes
Clean Code and Tests
22. @drpicox
@drpicox
WHO TESTS THE TEST?
22
TDD — THE RULES
Write a Test
✘ Test Fails
✔ Test Passes
Write the Code
✔ Test Passes
Clean Code and Tests
We know that code
works because tests.
We know that clean broke
nothing because tests.
It the test failing
who tests the test.
TDD SILVER RULE
You shall make tests fail
f
irst
25. @drpicox
@drpicox
TDD ESSENTIAL RULES
25
TDD — THE RULES
TDD GOLDEN RULE
You shall iterate fast
Write a Test
✘ Test Fails
✔ Test Passes
Write the Code
✔ Test Passes
Clean Code and Tests
30s
loop
26. @drpicox
@drpicox
DESIGN YOUR WAY
26
TDD — FIXING CODE SMELLS
Refactor
Code
time
speed
Refactor
Code
Refactor
Code
Refactor
Code
Refactor
Code
Refactor
Code
Refactor
Code
Refactor
Code
THE TDD
28. @drpicox
@drpicox
https://www.infoq.com/news/2014/06/tdd-dead-controversy/
KILLING TDD
28
TDD — IS DEAD
David Heinemeier Hansson, Ruby on Rails author and founder of Basecamp gave
the opening keynote at Railsconf 2014 in which he challenged the value of TDD as
it is often implemented.
«Then I'd try test-first for a few weeks, only to drop it again when it started
hurting my designs.»
«"Code that's hard to test in isolation is poorly designed", goes a common TDD maxim.
Isolation meaning free of dependent context and separated from collaborators […] The
prevalent definition of "unit" in unit testing (though not everyone agrees with this).»
«Such damage is defined as changes to your code that either facilitates a) easier test-
first, b) speedy tests, or c) unit tests, but does so by harming the clarity of the code
through […]. Code that is warped out of shape solely to accomodate testing objectives.»
29. @drpicox
@drpicox
https://wiki.c2.com/?DeveloperTest
THE REAL TDD
29
TDD — IS DEAD
Ward Cunningham, inventor of Wiki, writer of the Agile Manifesto, inventor of the
test runner and run docs as test, co-inventor of XP and TDD, inventor of the
technical debt concept.
«A DeveloperTest is the correct name for what the industry generally calls a UnitTest. It
is a test written for developers, as distinct from an AcceptanceTest or CustomerTest,
written for the OnsiteCustomers.»
«Under the strict definition, for QA purposes, the failure of a UnitTest implicates only
one unit. You know exactly where to search to find the bug.»
«TestDrivenDevelopment produces DeveloperTests. The failure of a test case implicates
only the developer’s most recent edit.»
30. @drpicox
@drpicox
BOTH AXIS
30
TDD — IS DEAD
+legible
-legible
legibility
DEVELOPER TEST ACCEPTANCE TEST
UNIT TEST
E2E TEST
con
f
idence
-con
f
idence
+con
f
idence
INTEGRATED TEST
Best compromise
Double Con
f
idence
It does what code says
Everyone on same page
Developers fail
with TDD because of
they use the wrong
level of abstraction
31. @drpicox
@drpicox
THE ELEPHANT IN THE ROOM
31
TDD — IS DEAD
XY-1516
The new valuable
feature
5
IT2
IT1 IT3 IT4
XY-
1516
XY-
1517
XY-
1518
AA-
1121
AA-
0987
AA-
1122
Last day of IT3
EV-1516 is not
yet
f
inished,
why is that?
Well, the PR is
stopped, it requires
cleaning
Today
ends the iteration,
and there are
dependencies
Approve
that and do
the cleaning
later.
Ok.
Keep technical excellence at all
times
Technical debt charges interest every
feature
No one wants a big refactor
SAFe is Agile
Story points are estimates, not time boxes
Never ever and ever ask for
termination
Ask for new estimates instead, and replan
Continuous attention to
technical excellence
and good design enhances
agility.
https://agilemanifesto.org
* Never congratulate a team for
32.
33. ff
erent primary value
«I had a problem. While using and teaching agile practices like test-driven development
(TDD) [...], I kept coming across the same confusion and misunderstandings.
Programmers wanted to know where to start, what to test and what not to test, how
much to test in one go, what to call their tests, and how to understand why a test fails.»
«I remember thinking “If only someone had told me that!” far more often than I
thought “Wow, a door has opened.” I decided it must be possible to present TDD in a
way that gets straight to the good stuff and avoids all the pitfalls.»
«At this point, I had a framework that helped me understand – and more importantly,
explain – how TDD works and an approach that avoided all the pitfalls I had
encountered.»
If we could develop a consistent vocabulary for analysts, testers, developers, and the
business, then we would be well on the way to eliminating some of the ambiguity and
miscommunication that occur when technical people talk to business people.
35. @drpicox
@drpicox
TDD SILVER RULE
You shall make tests fail
f
irst
BDD GOLDEN RULE
You shall have a common language
TDD
35
TDD — VS. TDD
TDD SILVER RULE
You shall make tests fail
f
irst
TDD GOLDEN RULE
You shall iterate fast
BDD
36. @drpicox
@drpicox
THE PATH
36
TDD — VS. BDD
Acceptance
Test
TDD
BDD
Developer
Test
Feature: Is it Friday yet?
Everybody wants to know when it's Friday
Scenario: Sunday isn't Friday
Given today is Sunday
When I ask whether it's Friday yet
Then I should be told "Nope"
import { isItFridayYet } from '../'
test('Sunday isn't Friday', () => {
const today = new Date('Sunday 8/16/2020');
const answer = isItFridayYet(today);
expect(answer).toBe(false);
});
PO QA Dev
Dev
37. @drpicox
@drpicox
BOTH AXIS
37
TDD — VS. BDD
+legible
-legible
legibility
DEVELOPER TEST ACCEPTANCE TEST
UNIT TEST
E2E TEST
con
f
idence
-con
f
idence
+con
f
idence
INTEGRATED TEST
Fast enough for TDD
Create suits and focus
Usually too slow for TDD
TDD
BDD
39. @drpicox
@drpicox
Focus the most important suit and run every
minute
Run all developer tests at least every two
hours
RUN TESTS FREQUENTLY
39
TDD — TIPS FOR ADOPTION
40. @drpicox
@drpicox
The code is who teaches to the new
members
Testing code should be cleaner than
production code
CODE IS YOUR FRIEND
40
TDD — TIPS FOR ADOPTION
41. @drpicox
@drpicox
Once a developer needs to run the
application to develop, TDD is over.
MANUAL TESTING IS YOUR ENEMY
41
TDD — TIPS FOR ADOPTION