SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Basic TDD Moves
Heuristics beyond “Red/Green/Refactor”
About me…
Developer since 1994
(C++ used to be my friend…)
Agile Coach since 2009
fernando.a.cuenca@gmail.com
@fer_cuenca
Big Thanks to our Sponsors!
http://lighthouselabs.ca	
  	
   http://devhub.ca	
  	
  
Agenda
  Basic TDD Moves
  Practice Session 1 + Debrief
  BREAK
  Practice Session 2 + Debrief
Start
Here
TDD
Write a
failing
test
Make it
pass
Improve
the
Design
The Three Laws
of TDD
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 sufficient to fail;
and compilation failures are failures.
3. You are not allowed to write any more
production code than is sufficient to
pass the one failing unit test.
http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
Robert “Uncle Bob” Martin
1, 2, , 4, , , 7, 8,
, , 11, , 13, 14,
, 16, 17, …
String result = "";
if((number % 3) == 0) result = "fizz";
if((number % 5) == 0) result += "buzz";
if(result.isEmpty())
result = number.toString();
return result;
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
fail(“niy”);
}
}
NIY Test
Step on solid ground from the very beginning
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
}
First Things First
Start by writing an assertion
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
}
public class FizzBuzz
{
public static int of(int number)
{
return 1;
}
}
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(2));
}
}
public class FizzBuzz
{
public static int of(int number)
{
return number;
}
}
Uncle Bob’s 3 Laws
Start with Failing Test
Sufficient enough to fail
Uncle Bob’s 3 Laws
Sufficient enough code to pass the test
Triangulation
Approximate with examples
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(2));
}
@Test public void test_fizzbuzz_3()
{
assertThat(FizzBuzz.of(3), is(“fizz”));
}
}
public class FizzBuzz
{
public static int of(int number)
{
return number;
}
}
Type mismatch!
Design is wrong!
We need
to go
here…
TDD
Write a
failing
test
Make it
pass
Improve
the
Design
But we’re
here!
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(2));
}
//@Test public void test_fizzbuzz_3()
//{
// assertThat(FizzBuzz.of(3), is(“fizz”));
//}
}
public class FizzBuzz
{
public static int of(int number)
{
return number;
}
}
Better Green than Sorry
Refactor only when tests are passing;
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(2));
}
//@Test public void test_fizzbuzz_3()
//{
// assertThat(FizzBuzz.of(3), is(“fizz”));
//}
}
public class FizzBuzz
{
public static of( number)
{
return number;
}
}
Better Green than Sorry
Keep all test passing while refactoring
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(1));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(2));
}
//@Test public void test_fizzbuzz_3()
//{
// assertThat(FizzBuzz.of(3), is(“fizz”));
//}
}
public class FizzBuzz
{
public static of(Integer number)
{
return ();
}
}
Predictable Failure
Refactoring against the Red Bar
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is( ));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is( ));
}
//@Test public void test_fizzbuzz_3()
//{
// assertThat(FizzBuzz.of(3), is(“fizz”));
//}
}
public class FizzBuzz
{
public static String of(Integer number)
{
return number.toString();
}
}
Better Green than Sorry
Run all the tests, all the time
The House is in Order
All tests must pass before writing
the next test
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(“1”));
}
@Test public void test_fizzbuzz_2()
{
assertThat(FizzBuzz.of(2), is(“2”));
}
@Test public void test_fizzbuzz_3()
{
assertThat(FizzBuzz.of(3), is(“fizz”));
}
@Test public void test_fizzbuzz_6()
{
assertThat(FizzBuzz.of(6), is(“fizz”));
}
@Test public void test_fizzbuzz_5()
{
assertThat(FizzBuzz.of(5), is(“buzz”));
}
@Test public void test_fizzbuzz_10()
{
assertThat(FizzBuzz.of(10), is(“buzz”));
}
@Test public void test_fizzbuzz_15()
{
assertThat(FizzBuzz.of(15), is(“fizzbuzz”));
}
}
public class FizzBuzz
{
public static String of(Integer number)
{
String result = "";
if((number % 3) == 0) result = "fizz";
if((number % 5) == 0) result += "buzz";
if(result.isEmpty())
result = number.toString();
return result;
}
}
public class FizzBuzzTests {
@Test public void test_fizzbuzz()
{
assertThat(FizzBuzz.of(1), is(“1”));
assertThat(FizzBuzz.of(2), is(“2”));
assertThat(FizzBuzz.of(3), is(“fizz”));
assertThat(FizzBuzz.of(6), is(“fizz”));
assertThat(FizzBuzz.of(5), is(“buzz”));
assertThat(FizzBuzz.of(10), is(“buzz”));
assertThat(FizzBuzz.of(15), is(“fizzbuzz”));
}
}
public class FizzBuzzTests {
@Test
public void returns_fizz_for_multiples_of_3() {
assertThat(FizzBuzz.of(3), is("fizz"));
assertThat(FizzBuzz.of(6), is("fizz"));
}
@Test
public void returns_buzz_for_multiples_of_5() {
assertThat(FizzBuzz.of(5), is("buzz"));
assertThat(FizzBuzz.of(10), is("buzz"));
}
@Test
public void returns_fizzbuzz_for_multiples_of_both_3_and_5()
{
assertThat(FizzBuzz.of(15), is("fizzbuzz"));
assertThat(FizzBuzz.of(30), is("fizzbuzz"));
}
@Test
public void returns_number_as_is_for_other_numbers()
{
assertThat(FizzBuzz.of(1), is("1"));
assertThat(FizzBuzz.of(2), is(“2"));
int bigNumber= 2 * 4 * 7 * 11 * 23;
assertThat(FizzBuzz.of(bigNumber),
is(Integer.toString(bigNumber)));
}
}
No Guessing Games
Test Names Reflect Intent
Assertive Minimalist
Test only “one thing”
public class FizzBuzzTests {
public void returns_fizz_for_multiples_of_3() {…}
public void returns_buzz_for_multiples_of_5() {…}
public void returns_fizzbuzz_for_multiples_of_both_3_and_5() {…}
public void returns_number_as_is_for_other_numbers() {…}
}
Kevlin Henney
“Programming with GUTS”
“Test Smells & Fragrances”
public class FizzBuzzTests {
@Test
public void returns_fizz_for_multiples_of_3() {
assertThat(FizzBuzz.of(3), is("fizz"));
assertThat(FizzBuzz.of(6), is("fizz"));
}
@Test
public void returns_buzz_for_multiples_of_5() {
assertThat(FizzBuzz.of(5), is("buzz"));
assertThat(FizzBuzz.of(10), is("buzz"));
}
@Test
public void returns_fizzbuzz_for_multiples_of_both_3_and_5()
{
assertThat(FizzBuzz.of(15), is("fizzbuzz"));
assertThat(FizzBuzz.of(30), is("fizzbuzz"));
}
@Test
public void returns_number_as_is_for_other_numbers()
{
assertThat(FizzBuzz.of(1), is("1"));
assertThat(FizzBuzz.of(2), is(“2"));
int bigNumber= 2 * 4 * 7 * 11 * 23;
assertThat(FizzBuzz.of(bigNumber),
is(Integer.toString(bigNumber)));
}
}
public class FizzBuzzTests {
@Test
public void returns_fizz_for_multiples_of_3() {
assertThatFizzbuzzForNumbersIs(“fizz”, 3, 6);
}
@Test
public void returns_buzz_for_multiples_of_5() {
assertThatFizzbuzzForNumbersIs(“buzz”, 5, 10);
}
@Test
public void returns_fizzbuzz_for_multiples_of_both_3_and_5()
{
assertThatFizzbuzzForNumbersIs(“fizzbuzz”, 15, 35);
}
@Test
public void returns_number_as_is_for_other_numbers()
{
int bigNumber= 2 * 4 * 7 * 11 * 23;
assertThatNumbersRemainAsIs(1, 2, bigNumber);
}
}
/* Custom Assertions */
private void assertThatFizzbuzForNumbersIs(
String expectedResult, int... numbers)
{
for(int n: numbers)
{
assertThat(
FizzBuzz.of(n), is(expectedResult));
}
}
private void assertThatNumbersRemainAsIs(
int... numbers)
{
for(Integer n: numbers)
{
assertThat(
FizzBuzz.of(n), is(n.toString()));
}
}
Duplication Fighter
No duplication in production or test code
Your turn now!
2 Practice Sessions on the
“String Calculator Kata”
  We need to choose a common Programming Language
  Find a partner (we’ll switch for Session 2)
  Log in to Cyber-Dojo: http://cyber-­‐dojo.org	
  	
  
Practice Session 1:
Basic TDD “Moves”
Uncle Bob’s Three Laws
Start with a failing test
Write enough of a test to fail
Write only the code that is sufficient to make the failing test pass
NIY Test Start on solid ground from the very beginning
First Things First Start the test by writing an assertion
Triangulation Approximate with examples
Keep the House in Order All tests must pass before moving on to the next test
Duplication Fighter
Remove duplication after a test passes
Keep the tests clean and free of duplication
Better Green than Sorry
Refactor only when all tests are passing
Re-run all tests after every refactoring
No Guessing Games Test names reflect intent
Assertive Minimalist Minimize the number of assertions (test "one thing”)
Predictable Failure Refactoring against the Red Bar
Debrief: What was it like?
  What are most important insights you gained from the
session?
  What was helpful / not-helpful?
  What will you do differently in the next session?
Practice Session 2:
Extreme Baby Steps
1.  Setup source control repository.
2.  Setup a timer for 2 minutes interval when you start.
3.  Write exactly one test
1. If the timer rings and the test is red then revert and start over.
2. If the test is green before timer rings then commit.
4. Restart timer (no discussions in between timers)
5. Refactor
1. If the timer rings and the refactoring is not complete then revert and start over.
2. If the refactoring is complete before the timer rings then commit.
6. Restart the timer (no discussions in between timers)
7. Go to 3.
http://blog.adrianbolboaca.ro/2013/03/taking-­‐baby-­‐steps	
  
Debrief: What was it like?
  What are most important insights you gained from this
session?
  What was the overall feeling?
  How does the result compares to what you initially
thought the outcome might be?
  How/Where could this approach be useful?
  What will you do differently tomorrow, back in the
office?
Learning more
Kevlin Henney Presentations
Programming with GUTS
https://www.infoq.com/presentations/testing-communication
Test Smells & Fragrances
https://www.youtube.com/watch?v=wCx_6kOo99M
Thank you!
And please, complete the feedback forms!!
Image Credits
  “Chess”, by John Croudy / used under CC
  Scales image from Wikipedia
  “Feedback”, buy Jurgen Appelo / used under CC

Contenu connexe

Tendances

Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Tom Crinson
 
SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019tech.kartenmacherei
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit TestingMike Lively
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Executable documentation
Executable documentationExecutable documentation
Executable documentationRussell Gold
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDPaweł Michalik
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to heroJeremy Cook
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best PracticesEdorian
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnitMindfire Solutions
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmanndpc
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::ClassCurtis Poe
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
Realizando Pruebas con Spock
Realizando Pruebas con SpockRealizando Pruebas con Spock
Realizando Pruebas con SpockAndres Almiray
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockitoMathieu Carbou
 

Tendances (20)

Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it. Test Driven Development: Why I hate it; but secretly love it.
Test Driven Development: Why I hate it; but secretly love it.
 
SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019SmokeTests - What, Why & How - ConFoo 2019
SmokeTests - What, Why & How - ConFoo 2019
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Executable documentation
Executable documentationExecutable documentation
Executable documentation
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::Class
 
TDD Hands-on
TDD Hands-onTDD Hands-on
TDD Hands-on
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Realizando Pruebas con Spock
Realizando Pruebas con SpockRealizando Pruebas con Spock
Realizando Pruebas con Spock
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 

Similaire à Basic TDD moves

Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
 
FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided KataMike Clement
 
Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDDrubocoptero
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Software Craftsmanship Alicante
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzFranklin Chen
 
Mutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsMutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsAri Waller
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Gianluca Padovani
 
When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)Uberto Barbini
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Gianluca Padovani
 
Mateusz Bryła - Mutation testing
Mateusz Bryła - Mutation testingMateusz Bryła - Mutation testing
Mateusz Bryła - Mutation testingkraqa
 
TDD - Unit testing done right and programmer happiness
TDD - Unit testing done right and programmer happinessTDD - Unit testing done right and programmer happiness
TDD - Unit testing done right and programmer happinessErez Cohen
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)vilniusjug
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiAgileee
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingunihack
 

Similaire à Basic TDD moves (20)

Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided Kata
 
Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDD
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzz
 
Mutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsMutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The Bugs
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry (IAD 2013)
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Mateusz Bryła - Mutation testing
Mateusz Bryła - Mutation testingMateusz Bryła - Mutation testing
Mateusz Bryła - Mutation testing
 
TDD - Unit testing done right and programmer happiness
TDD - Unit testing done right and programmer happinessTDD - Unit testing done right and programmer happiness
TDD - Unit testing done right and programmer happiness
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
 
Assorted TDD tips
Assorted TDD tipsAssorted TDD tips
Assorted TDD tips
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programing
 

Plus de Fernando Cuenca

Kanban: More than boards and WIP limits
Kanban: More than boards and WIP limitsKanban: More than boards and WIP limits
Kanban: More than boards and WIP limitsFernando Cuenca
 
Kanban: mucho Mas que tableros y Limites de WIP
Kanban: mucho Mas que tableros y Limites de WIPKanban: mucho Mas que tableros y Limites de WIP
Kanban: mucho Mas que tableros y Limites de WIPFernando Cuenca
 
Finding your Service Delivery Manager
Finding your Service Delivery ManagerFinding your Service Delivery Manager
Finding your Service Delivery ManagerFernando Cuenca
 
Agile Dependencies: When "going cross-functional" is not an option
Agile Dependencies: When "going cross-functional" is not an optionAgile Dependencies: When "going cross-functional" is not an option
Agile Dependencies: When "going cross-functional" is not an optionFernando Cuenca
 
Kanban in The Land of Scrum: Choose your Own Scrumban Adventure
Kanban in The Land of Scrum: Choose your Own Scrumban AdventureKanban in The Land of Scrum: Choose your Own Scrumban Adventure
Kanban in The Land of Scrum: Choose your Own Scrumban AdventureFernando Cuenca
 
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...Fernando Cuenca
 
Your board is trying to tell you something
Your board is trying to tell you somethingYour board is trying to tell you something
Your board is trying to tell you somethingFernando Cuenca
 
AgileLunch Meetup - Listen to your Board
AgileLunch Meetup - Listen to your BoardAgileLunch Meetup - Listen to your Board
AgileLunch Meetup - Listen to your BoardFernando Cuenca
 
Visualizing Work: If you can't see it, you can't manage it
Visualizing Work: If you can't see it, you can't manage itVisualizing Work: If you can't see it, you can't manage it
Visualizing Work: If you can't see it, you can't manage itFernando Cuenca
 
Kanban to #003 - Metrics
Kanban to #003 - MetricsKanban to #003 - Metrics
Kanban to #003 - MetricsFernando Cuenca
 
Test Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopTest Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopFernando Cuenca
 
Amp up your Agile Implementation with Systems Thinking
Amp up your Agile Implementation with Systems ThinkingAmp up your Agile Implementation with Systems Thinking
Amp up your Agile Implementation with Systems ThinkingFernando Cuenca
 

Plus de Fernando Cuenca (15)

Kanban: More than boards and WIP limits
Kanban: More than boards and WIP limitsKanban: More than boards and WIP limits
Kanban: More than boards and WIP limits
 
El Pivot Pragmatico
El Pivot PragmaticoEl Pivot Pragmatico
El Pivot Pragmatico
 
Kanban: mucho Mas que tableros y Limites de WIP
Kanban: mucho Mas que tableros y Limites de WIPKanban: mucho Mas que tableros y Limites de WIP
Kanban: mucho Mas que tableros y Limites de WIP
 
Finding your SDM
Finding your SDMFinding your SDM
Finding your SDM
 
Finding your Service Delivery Manager
Finding your Service Delivery ManagerFinding your Service Delivery Manager
Finding your Service Delivery Manager
 
Agile Dependencies: When "going cross-functional" is not an option
Agile Dependencies: When "going cross-functional" is not an optionAgile Dependencies: When "going cross-functional" is not an option
Agile Dependencies: When "going cross-functional" is not an option
 
Kanban in The Land of Scrum: Choose your Own Scrumban Adventure
Kanban in The Land of Scrum: Choose your Own Scrumban AdventureKanban in The Land of Scrum: Choose your Own Scrumban Adventure
Kanban in The Land of Scrum: Choose your Own Scrumban Adventure
 
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...
From Team Flow to System Flow to Customer Flow: Practical Tools to Keep Valua...
 
Que tan agiles somos?
Que tan agiles somos?Que tan agiles somos?
Que tan agiles somos?
 
Your board is trying to tell you something
Your board is trying to tell you somethingYour board is trying to tell you something
Your board is trying to tell you something
 
AgileLunch Meetup - Listen to your Board
AgileLunch Meetup - Listen to your BoardAgileLunch Meetup - Listen to your Board
AgileLunch Meetup - Listen to your Board
 
Visualizing Work: If you can't see it, you can't manage it
Visualizing Work: If you can't see it, you can't manage itVisualizing Work: If you can't see it, you can't manage it
Visualizing Work: If you can't see it, you can't manage it
 
Kanban to #003 - Metrics
Kanban to #003 - MetricsKanban to #003 - Metrics
Kanban to #003 - Metrics
 
Test Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopTest Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini Workshop
 
Amp up your Agile Implementation with Systems Thinking
Amp up your Agile Implementation with Systems ThinkingAmp up your Agile Implementation with Systems Thinking
Amp up your Agile Implementation with Systems Thinking
 

Dernier

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 

Dernier (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 

Basic TDD moves

  • 1. Basic TDD Moves Heuristics beyond “Red/Green/Refactor”
  • 2. About me… Developer since 1994 (C++ used to be my friend…) Agile Coach since 2009 fernando.a.cuenca@gmail.com @fer_cuenca
  • 3. Big Thanks to our Sponsors! http://lighthouselabs.ca     http://devhub.ca    
  • 4. Agenda   Basic TDD Moves   Practice Session 1 + Debrief   BREAK   Practice Session 2 + Debrief
  • 6. The Three Laws of TDD 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 sufficient to fail; and compilation failures are failures. 3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test. http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd Robert “Uncle Bob” Martin
  • 7. 1, 2, , 4, , , 7, 8, , , 11, , 13, 14, , 16, 17, …
  • 8. String result = ""; if((number % 3) == 0) result = "fizz"; if((number % 5) == 0) result += "buzz"; if(result.isEmpty()) result = number.toString(); return result;
  • 9. public class FizzBuzzTests { @Test public void test_fizzbuzz() { fail(“niy”); } } NIY Test Step on solid ground from the very beginning
  • 10. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } } First Things First Start by writing an assertion
  • 11. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } } public class FizzBuzz { public static int of(int number) { return 1; } }
  • 12. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(2)); } } public class FizzBuzz { public static int of(int number) { return number; } } Uncle Bob’s 3 Laws Start with Failing Test Sufficient enough to fail Uncle Bob’s 3 Laws Sufficient enough code to pass the test Triangulation Approximate with examples
  • 13. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(2)); } @Test public void test_fizzbuzz_3() { assertThat(FizzBuzz.of(3), is(“fizz”)); } } public class FizzBuzz { public static int of(int number) { return number; } } Type mismatch! Design is wrong! We need to go here… TDD Write a failing test Make it pass Improve the Design But we’re here!
  • 14. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(2)); } //@Test public void test_fizzbuzz_3() //{ // assertThat(FizzBuzz.of(3), is(“fizz”)); //} } public class FizzBuzz { public static int of(int number) { return number; } } Better Green than Sorry Refactor only when tests are passing;
  • 15. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(2)); } //@Test public void test_fizzbuzz_3() //{ // assertThat(FizzBuzz.of(3), is(“fizz”)); //} } public class FizzBuzz { public static of( number) { return number; } } Better Green than Sorry Keep all test passing while refactoring
  • 16. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(1)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(2)); } //@Test public void test_fizzbuzz_3() //{ // assertThat(FizzBuzz.of(3), is(“fizz”)); //} } public class FizzBuzz { public static of(Integer number) { return (); } } Predictable Failure Refactoring against the Red Bar
  • 17. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is( )); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is( )); } //@Test public void test_fizzbuzz_3() //{ // assertThat(FizzBuzz.of(3), is(“fizz”)); //} } public class FizzBuzz { public static String of(Integer number) { return number.toString(); } } Better Green than Sorry Run all the tests, all the time The House is in Order All tests must pass before writing the next test
  • 18. public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(“1”)); } @Test public void test_fizzbuzz_2() { assertThat(FizzBuzz.of(2), is(“2”)); } @Test public void test_fizzbuzz_3() { assertThat(FizzBuzz.of(3), is(“fizz”)); } @Test public void test_fizzbuzz_6() { assertThat(FizzBuzz.of(6), is(“fizz”)); } @Test public void test_fizzbuzz_5() { assertThat(FizzBuzz.of(5), is(“buzz”)); } @Test public void test_fizzbuzz_10() { assertThat(FizzBuzz.of(10), is(“buzz”)); } @Test public void test_fizzbuzz_15() { assertThat(FizzBuzz.of(15), is(“fizzbuzz”)); } } public class FizzBuzz { public static String of(Integer number) { String result = ""; if((number % 3) == 0) result = "fizz"; if((number % 5) == 0) result += "buzz"; if(result.isEmpty()) result = number.toString(); return result; } } public class FizzBuzzTests { @Test public void test_fizzbuzz() { assertThat(FizzBuzz.of(1), is(“1”)); assertThat(FizzBuzz.of(2), is(“2”)); assertThat(FizzBuzz.of(3), is(“fizz”)); assertThat(FizzBuzz.of(6), is(“fizz”)); assertThat(FizzBuzz.of(5), is(“buzz”)); assertThat(FizzBuzz.of(10), is(“buzz”)); assertThat(FizzBuzz.of(15), is(“fizzbuzz”)); } }
  • 19. public class FizzBuzzTests { @Test public void returns_fizz_for_multiples_of_3() { assertThat(FizzBuzz.of(3), is("fizz")); assertThat(FizzBuzz.of(6), is("fizz")); } @Test public void returns_buzz_for_multiples_of_5() { assertThat(FizzBuzz.of(5), is("buzz")); assertThat(FizzBuzz.of(10), is("buzz")); } @Test public void returns_fizzbuzz_for_multiples_of_both_3_and_5() { assertThat(FizzBuzz.of(15), is("fizzbuzz")); assertThat(FizzBuzz.of(30), is("fizzbuzz")); } @Test public void returns_number_as_is_for_other_numbers() { assertThat(FizzBuzz.of(1), is("1")); assertThat(FizzBuzz.of(2), is(“2")); int bigNumber= 2 * 4 * 7 * 11 * 23; assertThat(FizzBuzz.of(bigNumber), is(Integer.toString(bigNumber))); } } No Guessing Games Test Names Reflect Intent Assertive Minimalist Test only “one thing”
  • 20. public class FizzBuzzTests { public void returns_fizz_for_multiples_of_3() {…} public void returns_buzz_for_multiples_of_5() {…} public void returns_fizzbuzz_for_multiples_of_both_3_and_5() {…} public void returns_number_as_is_for_other_numbers() {…} } Kevlin Henney “Programming with GUTS” “Test Smells & Fragrances”
  • 21. public class FizzBuzzTests { @Test public void returns_fizz_for_multiples_of_3() { assertThat(FizzBuzz.of(3), is("fizz")); assertThat(FizzBuzz.of(6), is("fizz")); } @Test public void returns_buzz_for_multiples_of_5() { assertThat(FizzBuzz.of(5), is("buzz")); assertThat(FizzBuzz.of(10), is("buzz")); } @Test public void returns_fizzbuzz_for_multiples_of_both_3_and_5() { assertThat(FizzBuzz.of(15), is("fizzbuzz")); assertThat(FizzBuzz.of(30), is("fizzbuzz")); } @Test public void returns_number_as_is_for_other_numbers() { assertThat(FizzBuzz.of(1), is("1")); assertThat(FizzBuzz.of(2), is(“2")); int bigNumber= 2 * 4 * 7 * 11 * 23; assertThat(FizzBuzz.of(bigNumber), is(Integer.toString(bigNumber))); } }
  • 22. public class FizzBuzzTests { @Test public void returns_fizz_for_multiples_of_3() { assertThatFizzbuzzForNumbersIs(“fizz”, 3, 6); } @Test public void returns_buzz_for_multiples_of_5() { assertThatFizzbuzzForNumbersIs(“buzz”, 5, 10); } @Test public void returns_fizzbuzz_for_multiples_of_both_3_and_5() { assertThatFizzbuzzForNumbersIs(“fizzbuzz”, 15, 35); } @Test public void returns_number_as_is_for_other_numbers() { int bigNumber= 2 * 4 * 7 * 11 * 23; assertThatNumbersRemainAsIs(1, 2, bigNumber); } } /* Custom Assertions */ private void assertThatFizzbuzForNumbersIs( String expectedResult, int... numbers) { for(int n: numbers) { assertThat( FizzBuzz.of(n), is(expectedResult)); } } private void assertThatNumbersRemainAsIs( int... numbers) { for(Integer n: numbers) { assertThat( FizzBuzz.of(n), is(n.toString())); } } Duplication Fighter No duplication in production or test code
  • 24. 2 Practice Sessions on the “String Calculator Kata”   We need to choose a common Programming Language   Find a partner (we’ll switch for Session 2)   Log in to Cyber-Dojo: http://cyber-­‐dojo.org    
  • 25.
  • 26. Practice Session 1: Basic TDD “Moves” Uncle Bob’s Three Laws Start with a failing test Write enough of a test to fail Write only the code that is sufficient to make the failing test pass NIY Test Start on solid ground from the very beginning First Things First Start the test by writing an assertion Triangulation Approximate with examples Keep the House in Order All tests must pass before moving on to the next test Duplication Fighter Remove duplication after a test passes Keep the tests clean and free of duplication Better Green than Sorry Refactor only when all tests are passing Re-run all tests after every refactoring No Guessing Games Test names reflect intent Assertive Minimalist Minimize the number of assertions (test "one thing”) Predictable Failure Refactoring against the Red Bar
  • 27. Debrief: What was it like?   What are most important insights you gained from the session?   What was helpful / not-helpful?   What will you do differently in the next session?
  • 28. Practice Session 2: Extreme Baby Steps 1.  Setup source control repository. 2.  Setup a timer for 2 minutes interval when you start. 3.  Write exactly one test 1. If the timer rings and the test is red then revert and start over. 2. If the test is green before timer rings then commit. 4. Restart timer (no discussions in between timers) 5. Refactor 1. If the timer rings and the refactoring is not complete then revert and start over. 2. If the refactoring is complete before the timer rings then commit. 6. Restart the timer (no discussions in between timers) 7. Go to 3. http://blog.adrianbolboaca.ro/2013/03/taking-­‐baby-­‐steps  
  • 29. Debrief: What was it like?   What are most important insights you gained from this session?   What was the overall feeling?   How does the result compares to what you initially thought the outcome might be?   How/Where could this approach be useful?   What will you do differently tomorrow, back in the office?
  • 30. Learning more Kevlin Henney Presentations Programming with GUTS https://www.infoq.com/presentations/testing-communication Test Smells & Fragrances https://www.youtube.com/watch?v=wCx_6kOo99M
  • 31. Thank you! And please, complete the feedback forms!!
  • 32. Image Credits   “Chess”, by John Croudy / used under CC   Scales image from Wikipedia   “Feedback”, buy Jurgen Appelo / used under CC

Notes de l'éditeur

  1. This is the code you know you need to write
  2. We know that the final implementation can’t return hard-coded values. What test can I write that pushes the design in that direction?