SlideShare a Scribd company logo
1 of 64
Download to read offline
Die Kunst
der
kleinen Schritte
David Völkel
Softwerkskammer Lübeck
14.11.2019
David Völkel
XP Days Germany
09.11.2018
@davidvoelkel
codecentric
Software Craft Meetup Munich
#TDD
Disclaimer!
"It's the small steps part that distinguishes the
TDD amateurs from the TDD experts ...
Experts are able to take smaller Steps.“*
*James Shore
Leap*
* Leap Pattern aus Kent Becks "Responsive Design"
https://www.infoq.com/presentations/responsive-design
Image by Thor
Hohes Risiko
Initial State Target StateStep 1 State 1 Step 2 State 2 State n-1 Step nSteps …
Leap
Initial State Target StateStep 1 State 1 Step 2 State 2 State n-1 Step nSteps …
Fehler?Werteachse
0,00
0,25
0,50
0,75
1,00
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43
Erfolgswahrscheinlichkeit pro Schritt 0,95
Erfolgswahrscheinlichkeit
Anzahl Mikroschritte
Initial State Target StateStep 1 State 1 Step 2 State 2 State n-1 Step nSteps …
Kosten bei Fehler
zeitaufwändige
Suche nach Ursache
{
Stepping Stone*
* Stepping Stone Pattern aus Kent Becks "Responsive Design"
https://www.infoq.com/presentations/responsive-design
Image by Seattle Municipal Archives
Stepping Stone*
Initial State Target StateStep 1 State 1 Step 2 State 2 State n-1 Step nSteps …
Undo is your friend
Fehler schnell finden
Aber auch Tests häufig ausführen!
Gegenmittel
Schnelles Feedback
Kleine Schritte
Kontinuierlich Ausführen
discussion by Artem Kovyazin from the Noun Project
Refresh by creative outlet from the Noun Project
Leap Stepping Stone
Trade Off?
"Test 3 Problem"
String methodToImplement(String argument) {
if (conditionOn(argument)) {
return "Test 3 fake result";
}
if (otherConditionOn(argument)) {
return "Test 2 fake result";
}
return "Test 1 fake result";
}
Refactoring?
Refactoring
Von außen beobachtbares
Verhalten
bleibt gleich
Refactoring
Transformation*
Von außen beobachtbares
Verhalten
bleibt gleich
wird erweitert
* aus Transformation Priority Premise , Uncle Bob
TDD
RED GREEN
REFACTOR
Arten von Changes
RED GREEN
REFACTOR
Transformation
Refactoring
Triangulation
TDD
RED GREEN
REFACTOR
Green Bar
Patterns** aus "Test -Drivene Development by Example“, Kent Beck
TDD
RED GREEN
REFACTOR
Green Bar
Patterns
Triangulation
Fake it
Obvious Implementation
Fake Response
Fake Response Test 2 Test 2Generisch gemacht
„Refactoring" macht generisch
Alles implementierenTest 1 Test 1
Test 1
Test 1
Test 1
Test 1
Triangulation
Fake it
Obvious Implementation
„Refactoring" macht generischFake Response
Fake Response Test 2 Test 2Generisch gemacht
Alles implementierenTest 1 Test 1
Test 1
Test 1
Test 1
Test 1
Aufwand
Triangulation
Fake it
Obvious Implementation
„Refactoring" macht generischFake Response
Fake Response Test 2 Test 2Generisch gemacht
Alles implementierenTest 1 Test 1
Test 1
Test 1
Test 1
Test 1
Aufwand
vs
Risiko
Green Bar Patterns
Sweetspot
Triangulation
Fake it
Obvious Implementation
Logik
Struktur
Trivial
RED GREEN
„Klassisches Refactoring“
REFACTOR
Cleanup
Remove Duplication
Express Intent
Ziel
Wartbarkeit
RED GREEN
REFACTOR
Preparatory Refactoring*
"An example of preparatory refactoring",

Martin Fowler
Preparatory Refactoring
"Green Phase"
Implementation Test grün
„Grün Phase“
beim Triangulieren
"Green Phase"
TransformationPreparatory Refactoring
Ziel: Rot verkürzen
Test grün
Test grün
Implementation
RED GREEN
REFACTOR
Preparatory Refactoring*
"An example of preparatory refactoring",

Martin Fowler
"Green Phase"
Preparatory Refactoring
Test auskommentieren
Test
Test grün
Test grün
Implementation
TransformationTest
Parallel Change*
aka Expand & Contract
old
create
new
delete old
old not used
anymore
Parallel Change Pattern
aus Kent Becks "Responsive Design"
https://www.infoq.com/presentations/responsive-design
Auch beschrieben von Martin Fowler
https://martinfowler.com/bliki/ParallelChange.html
Transformation
Priority Premise*
Kontext
Versprechen
Auswahl nächster Testcase
Kleinere Schritte
Weniger „Steckenbleiben“
* "The Transformation Priority Premise", Uncle Bob
Prio 1 Trafo
Prio 2 Trafo
…
Prio n Trafo
Simpel
Komplex
Transformation
Priority Premise
Transformation in nächstem Test
Transformationen
1.({}–>nil)
2.(nil->constant)
3.(constant->constant+) WTF?
4.(constant->scalar)
5.(statement->statements)
6.(unconditional->if)
7.(scalar->array)
8.(array->container)
9.(statement->recursion)
10.(if->while)
11.(expression->function)
12.(variable->assignment)
* "The Transformation Priority Premise", Uncle Bob
*
Hypothese
1.({}–>nil)
2.(nil->constant)
3.(constant->constant+)
4.(constant->scalar)
5.(statement->statements)
6.(unconditional->if)
7.(scalar->array)
8.(array->container)
9.(statement->recursion)
10.(if->while)
11.(expression->function)
12.(variable->assignment)
0.Refactorings
Wahrscheinlichkeit
Erfolgswahrscheinlichkeit
Anzahl Mikroschritte
0
0,25
0,5
0,75
1
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43
0,99
0,95
0,9
0,8
1.({}–>nil)
2.(nil->constant)
3.(constant->constant+)
4.(constant->scalar)
5.(statement->statements)
6.(unconditional->if)
7.(scalar->array)
8.(array->container)
9.(statement->recursion)
10.(if->while)
11.(expression->function)
12.(variable->assignment)
0.Refactorings
Erfolgswahrscheinlichkeit
pro Schritt
Vorbereitende Refactorings
Trivialtestcases
Fake it "Refactoring"
Triangulation
Obvious Implementation
Mutable State
Green Bar & TPP?
1.({}–>nil)
2.(nil->constant)
3.(constant->constant+)
4.(constant->scalar)
5.(statement->statements)
6.(unconditional->if)
7.(scalar->array)
8.(array->container)
9.(statement->recursion)
10.(if->while)
11.(expression->function)
12.(variable->assignment)
Dekomposition
beim TDD
Inside-Out Outside-In
BOTTOM UP / INSIDE OUT
Unittest
BOTTOM UP / INSIDE OUT
Unittest
Unittest
BOTTOM UP / INSIDE OUT
Akzeptanztest
Akzeptanz-Test
GUI / Endpoint
TOP-DOWN / "OUTSIDE-IN"
Unittest
Mock
OUTSIDE-IN

MOCKING
Test
OUTSIDE-IN

MOCKING
GUI / Endpoint
Akzeptanztest
OUTSIDE-IN

FAKE-IT
Fake
Akzeptanztest
OUTSIDE-IN

FAKE-IT
Fake
Akzeptanztest Fake
OUTSIDE-IN

FAKE-IT
Unittest
Akzeptanztest
OUTSIDE-IN

FAKE-IT
Akzeptanztest
OUTSIDE-IN

FAKE-IT
Rückwärts rechnen
&
Triangulation mit virtuellen
Fakedaten
Fake it Outside-In
„Test 3“ Fake 3 result
Logik
Struktur & Dekomposition
Fake it
Triangulation
*Fake it Outside-In
*
Fake it Outside-In
Fake it "Refactoring“
„Test 3“
Trafo
Fake 3 result
Preparatory Refactoring
Logik
Struktur & Dekomposition
Fake it
Triangulation
Fake it Outside-In
Fake it "Refactoring“
„Test 3“
Trafo
Fake 3 result
Preparatory Refactoring
Logik
Struktur & Dekomposition
Fake it
Triangulation
Ggf. nachtriangulieren
Fake it Outside-In
Use Cases?
Fake it Triangulation
Use Cases?
Fake it
Struktur
Templating
Mapping
Dekomposition
Berechnungen
Collections/Iterationen
Triangulation
Logik
Conditionals
Rekursionen
Algorithmen
DATA GUIDES STRUCTURE
Triangulation Fake It
Structure Cumbersome Data guides well
# BRANCHES
Triangulation Fake It
# N 1
More confidence
More effort
# BRANCHES
Triangulation Fake It
# N 1
Fake data easy to forget
Omitting cases is tempting
TIME IN GREEN
Triangulation
Prep Refactoring
Triangulation
Fake It
Zu große Schritte
Risiken
Steckenbleiben beim TDD
Lange Fehlersuche
Gegenmittel
Hochpriore Changes zuerst
=> „Zeit im Rot“ minimieren
Kleine Schritte
Dekomposition
Vorbereitende Refactorings
Design bekannt: Outside-In/Inside-Out
Rückwärts rechnen
LicenseCreative Commons Attribution-ShareAlike 3.0

More Related Content

More from David Völkel

Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017David Völkel
 
Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days David Völkel
 
Fake It Outside-In TDD @XP2017
Fake It Outside-In TDD @XP2017Fake It Outside-In TDD @XP2017
Fake It Outside-In TDD @XP2017David Völkel
 
Fake It Outside-In TDD
Fake It Outside-In TDDFake It Outside-In TDD
Fake It Outside-In TDDDavid Völkel
 
Mockist vs Classicists TDD
Mockist vs Classicists TDDMockist vs Classicists TDD
Mockist vs Classicists TDDDavid Völkel
 
Wann soll ich mocken?
Wann soll ich mocken?Wann soll ich mocken?
Wann soll ich mocken?David Völkel
 
Transformation Priority Premise @Softwerkskammer MUC
Transformation Priority Premise @Softwerkskammer MUCTransformation Priority Premise @Softwerkskammer MUC
Transformation Priority Premise @Softwerkskammer MUCDavid Völkel
 
Mockist vs. Classicists TDD
Mockist vs. Classicists TDDMockist vs. Classicists TDD
Mockist vs. Classicists TDDDavid Völkel
 
Infrastructure as Code for Beginners
Infrastructure as Code for BeginnersInfrastructure as Code for Beginners
Infrastructure as Code for BeginnersDavid Völkel
 
Unit vs. Integration Tests
Unit vs. Integration TestsUnit vs. Integration Tests
Unit vs. Integration TestsDavid Völkel
 
Integration Test Hell
Integration Test HellIntegration Test Hell
Integration Test HellDavid Völkel
 
Baby Steps TDD Approaches
Baby Steps TDD ApproachesBaby Steps TDD Approaches
Baby Steps TDD ApproachesDavid Völkel
 
Clean Test Code (Clean Code Days)
Clean Test Code (Clean Code Days)Clean Test Code (Clean Code Days)
Clean Test Code (Clean Code Days)David Völkel
 
Mockist vs. Classicists TDD
Mockist vs. Classicists TDDMockist vs. Classicists TDD
Mockist vs. Classicists TDDDavid Völkel
 
Wie wird mein Code testbar?
Wie wird mein Code testbar?Wie wird mein Code testbar?
Wie wird mein Code testbar?David Völkel
 

More from David Völkel (17)

Trade Off!
Trade Off!Trade Off!
Trade Off!
 
Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017Global Day of Coderetreat Munich 2017
Global Day of Coderetreat Munich 2017
 
Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days Fake It Outside-In TDD Workshop @ Clean Code Days
Fake It Outside-In TDD Workshop @ Clean Code Days
 
Fake It Outside-In TDD @XP2017
Fake It Outside-In TDD @XP2017Fake It Outside-In TDD @XP2017
Fake It Outside-In TDD @XP2017
 
Fake It Outside-In TDD
Fake It Outside-In TDDFake It Outside-In TDD
Fake It Outside-In TDD
 
Mockist vs Classicists TDD
Mockist vs Classicists TDDMockist vs Classicists TDD
Mockist vs Classicists TDD
 
Wann soll ich mocken?
Wann soll ich mocken?Wann soll ich mocken?
Wann soll ich mocken?
 
Transformation Priority Premise @Softwerkskammer MUC
Transformation Priority Premise @Softwerkskammer MUCTransformation Priority Premise @Softwerkskammer MUC
Transformation Priority Premise @Softwerkskammer MUC
 
Mockist vs. Classicists TDD
Mockist vs. Classicists TDDMockist vs. Classicists TDD
Mockist vs. Classicists TDD
 
Infrastructure as Code for Beginners
Infrastructure as Code for BeginnersInfrastructure as Code for Beginners
Infrastructure as Code for Beginners
 
Unit vs. Integration Tests
Unit vs. Integration TestsUnit vs. Integration Tests
Unit vs. Integration Tests
 
Integration Test Hell
Integration Test HellIntegration Test Hell
Integration Test Hell
 
Baby Steps TDD Approaches
Baby Steps TDD ApproachesBaby Steps TDD Approaches
Baby Steps TDD Approaches
 
Clean Test Code (Clean Code Days)
Clean Test Code (Clean Code Days)Clean Test Code (Clean Code Days)
Clean Test Code (Clean Code Days)
 
Clean Test Code
Clean Test CodeClean Test Code
Clean Test Code
 
Mockist vs. Classicists TDD
Mockist vs. Classicists TDDMockist vs. Classicists TDD
Mockist vs. Classicists TDD
 
Wie wird mein Code testbar?
Wie wird mein Code testbar?Wie wird mein Code testbar?
Wie wird mein Code testbar?
 

Die Kunst der kleinen Schritte - Softwerkskammer Lübeck