SlideShare a Scribd company logo
1 of 29
Pitfalls of TDD Adoption

     Bartosz Baokowski
Agenda
•   Intro
•   What is TDD?
•   Why to adopt it?
•   Experience
•   Test smells and patterns
•   Summary
•   Where to go next?
About the author
•   Software developer
•   Agile coach/mentor
•   Open source contributor
•   Leader of Polish Agile User Group
What is TDD?
• It seems everyone knows it nowadays.
• At least everyone talks about it.
• Well, why do we still have bad code?
Why to adopt it?
•   Explore system behavior.
•   Create a specification.
•   Drive code design.
•   Think about quality.
•   Last, but not least – build executable and
    automated tests.
Experience
• TDD classes on major universities in Krakow,
  Poland since 2007.
• TDD workshops at various conferences in
  Poland.
• TDD coaching and trainings at Sabre Holdings.
The Good, The Bad & The Ugly
      aka what to do and what to avoid in your tests
What to test?
• Methods vs Test Cases = 1:1 relationship
• How to name a test method?
    class Flights {            class FlightsTest {
      addFlight(...);            testAddFlight(...);
      getFlight(...);            testGetFlight(...);
      getFlightSeats(...);       testGetFlightSeats(...);
      getCheapestSeat(...);      testGetCheapestSeat(...);
      bookSeat(...);             testBookSeat(...);
    }                          }
What to test?
• Implicit constructor testing
        @Test
        public void testConstructor() {
          Flight flight = new Flight();
          assertEquals(...);
          assertEquals(...);
        }

        @Test
         public void testConstructor() {
          Flight flight = new Flight();
          assertNotNull(flight);
        }
It’s about behavior
• ...so write examples:
  – tell me what your system does NOT have yet?
  – answer it in programming language
  – answer giving an example
Coding by example
• User story:
   – As a user I want to get a number of available seats for a
     given flight
         class FlightTest {

             @Test
             public void shouldReturnNumberOfAvailableSeats() {
              // given
              Flight flight = new Flight();
              flight.addSeats(10);

                 // when
                 int numberOfSeats = flight.getNumberOfAvailableSeats();

                 // then
                 assertEquals(10, numberOfSeats);
             }

         }
Ultimate Test Template
@Test
public void should...() throws Exception {
 //given
 ...

    //when
    ...

    //then
    ...
}
„Should”
Reduce the chance tests will look like:




But increase the
  chance for:
Comments
//given
 ...

//when
...

//then
...


  Increase the chance the test is focused around
  single behavior.
Bloated fixture
• One fixture to rule them all


                          Test method 1
         Fixture
                          Test method 2

                          Test method 3

                          Test method 4
Healthy fixture
• Extract only common parts to setup method
                         @Test
You want to avoid it.
                         public void testAvailableSeatsCount() throws {
                           assertEquals(0, f.getAvailableSeats());
                           f.addSeat(new Seat(1, 100));
                           assertEquals(1, f.getAvailableSeats());
                         }


• Minimize it
• Use creation methods where appropriate
Minimal fixture
Noisy fixture
// given
Flight flight1 = new Flight(1, new Market("KRK", "YVR"), new Date(), 50);
Flight flight2 = new Flight(2, new Market("KRK", "YVR"), new Date(), 30);
Flight flight3 = new Flight(3, new Market("HKG", "YVR"), new Date(), 60);
List<Flight> flights = new ArrayList<Flight>();
flights.add(flight1);
flights.add(flight2);
flights.add(flight3);
FlightManager flightManger = new FlightManager(flights);

// when
List<Flight> flights = flightManger .getFlightsFromOrigin("KRK");

// then
assertEquals(2, flights.size());
assertTrue(flights.contains(flight1));
assertTrue(flights.contains(flight2));
Noisy fixture refactoring
• Hide irrelevant data with creation method
      // given
      Flight flight1 = createFlightFromOrigin("KRK");
      Flight flight2 = createFlightFromOrigin("KRK");
      Flight flight3 = createFlightFromOrigin("HKG");
• Make it simple
      List<Flight> flights = new ArrayList<Flight>();
      flights.add(flight1);
      flights.add(flight2);
      flights.add(flight3);
      FlightManager flightManger = new FlightManager(flights);



FlightManager flightManager = new FlightManager(asList(flight1, flight2, flight3));
Fluent builders
• Make code more readable
• Worth to try if too many creation methods
• Require time to build
  Flight flight = new Flight(1, new Market("KRK", "YVR"), new Date());




     Flight flight = buildFlight().number(1).between("KRK", "YVR").today().build();
Stable test data
• Golden rule:
  – No matter how many times you run the test it
    should always give the same results!
• Random test data
• Time & date tests can be tricky
One behavior per method
• If you have more than one statement in when,
  you may need a new example.
• If you have assertions outside then, you may
  need a new example.
One verification per test
• Use assertions only in then block
• Make them as expressive as possible
  assertEquals(2, flights.size());
  assertTrue(flights.contains(flight1));
  assertTrue(flights.contains(flight2));

                Custom assertion:
                assertFlightsContainOnly(flights, flight1, flight2);

                Hamcerst:
                assertThat(flights, hasItems(flight1, flight2));

                FEST-Assert:
                assertThat(flights).containsOnly(flight1, flight2);
Simplify assertions
• You don’t want to guess what you are
  expecting. It’s expectation anyway!
     assertEquals((a + b + c) / 3, average);

• Loops are bad.
      int pos = 0;
      for (ToolGroup group: groups) {
        assertTrue(pos <= group.getLocation());
        pos = group.getLocation();
      }
Simplify assertions
• Never use conditionals!
  – You definately need a new example
  – ...or your example is broken
Testing exceptions
• It seems fine:
     @Test(expected=IllegalFlightNumberException.class)
     public void shouldFailForWrongFlightNumber() throws Exception {
       FlightManager flightManager = new FlightManager();
       flightManager.addFlight(new Flight(10));
       flightManager.addFlight(new Flight(15));
       flightManager.getFlight(50);
     }


• But what if new Flight() can throw same
  exception?
Summary
How to make it work?
• Train your people
• Give them simple rules to adhere to (e.g. test
  template!)
• Encourage pair programming
• ...or at least code reviews
• Do not listen to excuses
  – I don’t have time to write tests!
Where to go next?
• Online:
  – xunitpatterns.com
  – behavior-driven.org
• Offline:
  – „xUnit Test Patterns” by Gerard Meszaros
  – „Growing Object-Oriented Software, Guided by
    Tests” by Steve Freeman, Nat Pryce
  – „Behavior Driven Development in Ruby with
    RSpec” by David Chelimsky, Aslak Hellesoy

More Related Content

What's hot

Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Hong Le Van
 
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
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)Foyzul Karim
 
Adding Unit Test To Legacy Code
Adding Unit Test To Legacy CodeAdding Unit Test To Legacy Code
Adding Unit Test To Legacy CodeTerry Yin
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)jaxLondonConference
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Howsatesgoral
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An IntroductionGiorgio Vespucci
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy CodeAdam Culp
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard partsShaun Abram
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
 

What's hot (20)

Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
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
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
Adding Unit Test To Legacy Code
Adding Unit Test To Legacy CodeAdding Unit Test To Legacy Code
Adding Unit Test To Legacy Code
 
ES3-2020-05 Testing
ES3-2020-05 TestingES3-2020-05 Testing
ES3-2020-05 Testing
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Hows
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 

Viewers also liked

How To Change The World
How To Change The WorldHow To Change The World
How To Change The WorldAgileee
 
Revisión bibliografica del bacilo mycobacterium tuberculosis
Revisión bibliografica del bacilo mycobacterium tuberculosisRevisión bibliografica del bacilo mycobacterium tuberculosis
Revisión bibliografica del bacilo mycobacterium tuberculosisJean Carlos Mendez Quezada
 
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)Wojciech Seliga
 
Project voldemort - When relation database is not enough (too much?)
Project voldemort - When relation database is not enough (too much?)Project voldemort - When relation database is not enough (too much?)
Project voldemort - When relation database is not enough (too much?)nurkiewicz
 
Collaborazione: da gruppo a team
Collaborazione: da gruppo a teamCollaborazione: da gruppo a team
Collaborazione: da gruppo a teammorettoNik
 
Przetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowychPrzetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowychleafnode
 
Continuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukContinuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukMarcinStachniuk
 
Zarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychZarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychMarcinStachniuk
 
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychLiquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychMarcinStachniuk
 
Presentacion final
Presentacion finalPresentacion final
Presentacion finalAdela Rivas
 
Creating HTML Pages
Creating HTML PagesCreating HTML Pages
Creating HTML PagesMike Crabb
 
New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0Mike Taylor
 

Viewers also liked (20)

How To Change The World
How To Change The WorldHow To Change The World
How To Change The World
 
Revisión bibliografica del bacilo mycobacterium tuberculosis
Revisión bibliografica del bacilo mycobacterium tuberculosisRevisión bibliografica del bacilo mycobacterium tuberculosis
Revisión bibliografica del bacilo mycobacterium tuberculosis
 
Communicating Science
Communicating ScienceCommunicating Science
Communicating Science
 
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)
How to be Awesome at a Java Developer Job Interview (Confitura 2012, Polish)
 
Project voldemort - When relation database is not enough (too much?)
Project voldemort - When relation database is not enough (too much?)Project voldemort - When relation database is not enough (too much?)
Project voldemort - When relation database is not enough (too much?)
 
Collaborazione: da gruppo a team
Collaborazione: da gruppo a teamCollaborazione: da gruppo a team
Collaborazione: da gruppo a team
 
Przetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowychPrzetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowych
 
CRITHINKEDU Overview (Portuguese)
CRITHINKEDU Overview (Portuguese)CRITHINKEDU Overview (Portuguese)
CRITHINKEDU Overview (Portuguese)
 
RANA AZHAR HUSSAIN
RANA AZHAR HUSSAINRANA AZHAR HUSSAIN
RANA AZHAR HUSSAIN
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
Liquibase w praktyce
Liquibase w praktyceLiquibase w praktyce
Liquibase w praktyce
 
Retrospekcja warsztat Agile3M
Retrospekcja warsztat Agile3MRetrospekcja warsztat Agile3M
Retrospekcja warsztat Agile3M
 
Continuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukContinuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin Stachniuk
 
Zarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danychZarządzanie zamianami w relacyjnych bazach danych
Zarządzanie zamianami w relacyjnych bazach danych
 
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danychLiquibase - Zarządzanie zmianami w relacyjnych bazach danych
Liquibase - Zarządzanie zmianami w relacyjnych bazach danych
 
Different job roles
Different job rolesDifferent job roles
Different job roles
 
Martín Luther King
Martín Luther KingMartín Luther King
Martín Luther King
 
Presentacion final
Presentacion finalPresentacion final
Presentacion final
 
Creating HTML Pages
Creating HTML PagesCreating HTML Pages
Creating HTML Pages
 
New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0New Amazing Things about AngularJS 2.0
New Amazing Things about AngularJS 2.0
 

Similar to Pitfalls Of Tdd Adoption by Bartosz Bankowski

Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2Yi-Huan Chan
 
Developer Test - Things to Know
Developer Test - Things to KnowDeveloper Test - Things to Know
Developer Test - Things to Knowvilniusjug
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittestFariz Darari
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
Testing Code and Assuring Quality
Testing Code and Assuring QualityTesting Code and Assuring Quality
Testing Code and Assuring QualityKent Cowgill
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Fariz Darari
 
GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?Patrick Lam
 
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
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#Rohit Rao
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingAnna Khabibullina
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 

Similar to Pitfalls Of Tdd Adoption by Bartosz Bankowski (20)

Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Developer Test - Things to Know
Developer Test - Things to KnowDeveloper Test - Things to Know
Developer Test - Things to Know
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Testing Code and Assuring Quality
Testing Code and Assuring QualityTesting Code and Assuring Quality
Testing Code and Assuring Quality
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
 
GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?
 
3 j unit
3 j unit3 j unit
3 j unit
 
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)
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 

More from Agileee

Robin Dymond: "Your Brain and Better Product Development"
Robin Dymond: "Your Brain and Better Product Development"Robin Dymond: "Your Brain and Better Product Development"
Robin Dymond: "Your Brain and Better Product Development"Agileee
 
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...Agileee
 
Piotr Burdylo: Managing developers is complex
Piotr Burdylo: Managing developers is complexPiotr Burdylo: Managing developers is complex
Piotr Burdylo: Managing developers is complexAgileee
 
Nick Oostvogels: 5 Arguments Against Kanban
Nick Oostvogels: 5 Arguments Against KanbanNick Oostvogels: 5 Arguments Against Kanban
Nick Oostvogels: 5 Arguments Against KanbanAgileee
 
Anthony Marchenko: Опыт внедрения Kanban
Anthony Marchenko: Опыт внедрения KanbanAnthony Marchenko: Опыт внедрения Kanban
Anthony Marchenko: Опыт внедрения KanbanAgileee
 
Nataliya Trenina: Office magic
Nataliya Trenina: Office magicNataliya Trenina: Office magic
Nataliya Trenina: Office magicAgileee
 
Henrik Kniberg: Agile at home
Henrik Kniberg: Agile at homeHenrik Kniberg: Agile at home
Henrik Kniberg: Agile at homeAgileee
 
Henrik Kniberg: Lean from the Trenches keynote @ AgileEE
Henrik Kniberg: Lean from the Trenches keynote @ AgileEEHenrik Kniberg: Lean from the Trenches keynote @ AgileEE
Henrik Kniberg: Lean from the Trenches keynote @ AgileEEAgileee
 
Nathaniel Cadwell: The Art of Facilitation
Nathaniel Cadwell: The Art of Facilitation Nathaniel Cadwell: The Art of Facilitation
Nathaniel Cadwell: The Art of Facilitation Agileee
 
Scrum and kanban
Scrum and kanbanScrum and kanban
Scrum and kanbanAgileee
 
The Extreme Decade
The Extreme DecadeThe Extreme Decade
The Extreme DecadeAgileee
 
Agile Testing. Risks, Uncertainty and Why It All Works
Agile Testing. Risks, Uncertainty and Why It All WorksAgile Testing. Risks, Uncertainty and Why It All Works
Agile Testing. Risks, Uncertainty and Why It All WorksAgileee
 
Movivation 3.0
Movivation 3.0Movivation 3.0
Movivation 3.0Agileee
 
Effective Software Development in the 21st Century
Effective Software Development in the 21st CenturyEffective Software Development in the 21st Century
Effective Software Development in the 21st CenturyAgileee
 
Myths, Legends and Monsters of Enterprise Agility
Myths, Legends and Monsters of Enterprise AgilityMyths, Legends and Monsters of Enterprise Agility
Myths, Legends and Monsters of Enterprise AgilityAgileee
 
Lightening Talk: Software craftsmanship
Lightening Talk: Software craftsmanshipLightening Talk: Software craftsmanship
Lightening Talk: Software craftsmanshipAgileee
 
Lightening Talk: Lean start up
Lightening Talk: Lean start upLightening Talk: Lean start up
Lightening Talk: Lean start upAgileee
 
Lightening Talk: lama sutra of retrospective
Lightening Talk: lama sutra of retrospectiveLightening Talk: lama sutra of retrospective
Lightening Talk: lama sutra of retrospectiveAgileee
 
Lightening Talk: Just do it eng
Lightening Talk: Just do it engLightening Talk: Just do it eng
Lightening Talk: Just do it engAgileee
 
Lightening Talk: Why do they leave
Lightening Talk: Why do they leaveLightening Talk: Why do they leave
Lightening Talk: Why do they leaveAgileee
 

More from Agileee (20)

Robin Dymond: "Your Brain and Better Product Development"
Robin Dymond: "Your Brain and Better Product Development"Robin Dymond: "Your Brain and Better Product Development"
Robin Dymond: "Your Brain and Better Product Development"
 
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...
Lyssa Adkins & Michael Spayd: The Essential Transformations: How Agile Calls ...
 
Piotr Burdylo: Managing developers is complex
Piotr Burdylo: Managing developers is complexPiotr Burdylo: Managing developers is complex
Piotr Burdylo: Managing developers is complex
 
Nick Oostvogels: 5 Arguments Against Kanban
Nick Oostvogels: 5 Arguments Against KanbanNick Oostvogels: 5 Arguments Against Kanban
Nick Oostvogels: 5 Arguments Against Kanban
 
Anthony Marchenko: Опыт внедрения Kanban
Anthony Marchenko: Опыт внедрения KanbanAnthony Marchenko: Опыт внедрения Kanban
Anthony Marchenko: Опыт внедрения Kanban
 
Nataliya Trenina: Office magic
Nataliya Trenina: Office magicNataliya Trenina: Office magic
Nataliya Trenina: Office magic
 
Henrik Kniberg: Agile at home
Henrik Kniberg: Agile at homeHenrik Kniberg: Agile at home
Henrik Kniberg: Agile at home
 
Henrik Kniberg: Lean from the Trenches keynote @ AgileEE
Henrik Kniberg: Lean from the Trenches keynote @ AgileEEHenrik Kniberg: Lean from the Trenches keynote @ AgileEE
Henrik Kniberg: Lean from the Trenches keynote @ AgileEE
 
Nathaniel Cadwell: The Art of Facilitation
Nathaniel Cadwell: The Art of Facilitation Nathaniel Cadwell: The Art of Facilitation
Nathaniel Cadwell: The Art of Facilitation
 
Scrum and kanban
Scrum and kanbanScrum and kanban
Scrum and kanban
 
The Extreme Decade
The Extreme DecadeThe Extreme Decade
The Extreme Decade
 
Agile Testing. Risks, Uncertainty and Why It All Works
Agile Testing. Risks, Uncertainty and Why It All WorksAgile Testing. Risks, Uncertainty and Why It All Works
Agile Testing. Risks, Uncertainty and Why It All Works
 
Movivation 3.0
Movivation 3.0Movivation 3.0
Movivation 3.0
 
Effective Software Development in the 21st Century
Effective Software Development in the 21st CenturyEffective Software Development in the 21st Century
Effective Software Development in the 21st Century
 
Myths, Legends and Monsters of Enterprise Agility
Myths, Legends and Monsters of Enterprise AgilityMyths, Legends and Monsters of Enterprise Agility
Myths, Legends and Monsters of Enterprise Agility
 
Lightening Talk: Software craftsmanship
Lightening Talk: Software craftsmanshipLightening Talk: Software craftsmanship
Lightening Talk: Software craftsmanship
 
Lightening Talk: Lean start up
Lightening Talk: Lean start upLightening Talk: Lean start up
Lightening Talk: Lean start up
 
Lightening Talk: lama sutra of retrospective
Lightening Talk: lama sutra of retrospectiveLightening Talk: lama sutra of retrospective
Lightening Talk: lama sutra of retrospective
 
Lightening Talk: Just do it eng
Lightening Talk: Just do it engLightening Talk: Just do it eng
Lightening Talk: Just do it eng
 
Lightening Talk: Why do they leave
Lightening Talk: Why do they leaveLightening Talk: Why do they leave
Lightening Talk: Why do they leave
 

Recently uploaded

Introducing to billionaire brain wave.pdf
Introducing to billionaire brain wave.pdfIntroducing to billionaire brain wave.pdf
Introducing to billionaire brain wave.pdfnoumannajam04
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..nishakur201
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceanilsa9823
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...anilsa9823
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndPooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceanilsa9823
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
Independent Escorts in Lucknow (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...
Independent Escorts in Lucknow  (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...Independent Escorts in Lucknow  (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...
Independent Escorts in Lucknow (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...gurkirankumar98700
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666nishakur201
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfJess Walker
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...CIOWomenMagazine
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theorydrae5
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxABMWeaklings
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 

Recently uploaded (20)

Introducing to billionaire brain wave.pdf
Introducing to billionaire brain wave.pdfIntroducing to billionaire brain wave.pdf
Introducing to billionaire brain wave.pdf
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
Independent Escorts in Lucknow (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...
Independent Escorts in Lucknow  (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...Independent Escorts in Lucknow  (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...
Independent Escorts in Lucknow (Adult Only) 👩🏽‍❤️‍💋‍👩🏼 8923113531 ♛ Escort S...
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptx
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 

Pitfalls Of Tdd Adoption by Bartosz Bankowski

  • 1. Pitfalls of TDD Adoption Bartosz Baokowski
  • 2. Agenda • Intro • What is TDD? • Why to adopt it? • Experience • Test smells and patterns • Summary • Where to go next?
  • 3. About the author • Software developer • Agile coach/mentor • Open source contributor • Leader of Polish Agile User Group
  • 4. What is TDD? • It seems everyone knows it nowadays. • At least everyone talks about it. • Well, why do we still have bad code?
  • 5. Why to adopt it? • Explore system behavior. • Create a specification. • Drive code design. • Think about quality. • Last, but not least – build executable and automated tests.
  • 6. Experience • TDD classes on major universities in Krakow, Poland since 2007. • TDD workshops at various conferences in Poland. • TDD coaching and trainings at Sabre Holdings.
  • 7. The Good, The Bad & The Ugly aka what to do and what to avoid in your tests
  • 8. What to test? • Methods vs Test Cases = 1:1 relationship • How to name a test method? class Flights { class FlightsTest { addFlight(...); testAddFlight(...); getFlight(...); testGetFlight(...); getFlightSeats(...); testGetFlightSeats(...); getCheapestSeat(...); testGetCheapestSeat(...); bookSeat(...); testBookSeat(...); } }
  • 9. What to test? • Implicit constructor testing @Test public void testConstructor() { Flight flight = new Flight(); assertEquals(...); assertEquals(...); } @Test public void testConstructor() { Flight flight = new Flight(); assertNotNull(flight); }
  • 10. It’s about behavior • ...so write examples: – tell me what your system does NOT have yet? – answer it in programming language – answer giving an example
  • 11. Coding by example • User story: – As a user I want to get a number of available seats for a given flight class FlightTest { @Test public void shouldReturnNumberOfAvailableSeats() { // given Flight flight = new Flight(); flight.addSeats(10); // when int numberOfSeats = flight.getNumberOfAvailableSeats(); // then assertEquals(10, numberOfSeats); } }
  • 12. Ultimate Test Template @Test public void should...() throws Exception { //given ... //when ... //then ... }
  • 13. „Should” Reduce the chance tests will look like: But increase the chance for:
  • 14. Comments //given ... //when ... //then ... Increase the chance the test is focused around single behavior.
  • 15. Bloated fixture • One fixture to rule them all Test method 1 Fixture Test method 2 Test method 3 Test method 4
  • 16. Healthy fixture • Extract only common parts to setup method @Test You want to avoid it. public void testAvailableSeatsCount() throws { assertEquals(0, f.getAvailableSeats()); f.addSeat(new Seat(1, 100)); assertEquals(1, f.getAvailableSeats()); } • Minimize it • Use creation methods where appropriate
  • 18. Noisy fixture // given Flight flight1 = new Flight(1, new Market("KRK", "YVR"), new Date(), 50); Flight flight2 = new Flight(2, new Market("KRK", "YVR"), new Date(), 30); Flight flight3 = new Flight(3, new Market("HKG", "YVR"), new Date(), 60); List<Flight> flights = new ArrayList<Flight>(); flights.add(flight1); flights.add(flight2); flights.add(flight3); FlightManager flightManger = new FlightManager(flights); // when List<Flight> flights = flightManger .getFlightsFromOrigin("KRK"); // then assertEquals(2, flights.size()); assertTrue(flights.contains(flight1)); assertTrue(flights.contains(flight2));
  • 19. Noisy fixture refactoring • Hide irrelevant data with creation method // given Flight flight1 = createFlightFromOrigin("KRK"); Flight flight2 = createFlightFromOrigin("KRK"); Flight flight3 = createFlightFromOrigin("HKG"); • Make it simple List<Flight> flights = new ArrayList<Flight>(); flights.add(flight1); flights.add(flight2); flights.add(flight3); FlightManager flightManger = new FlightManager(flights); FlightManager flightManager = new FlightManager(asList(flight1, flight2, flight3));
  • 20. Fluent builders • Make code more readable • Worth to try if too many creation methods • Require time to build Flight flight = new Flight(1, new Market("KRK", "YVR"), new Date()); Flight flight = buildFlight().number(1).between("KRK", "YVR").today().build();
  • 21. Stable test data • Golden rule: – No matter how many times you run the test it should always give the same results! • Random test data • Time & date tests can be tricky
  • 22. One behavior per method • If you have more than one statement in when, you may need a new example. • If you have assertions outside then, you may need a new example.
  • 23. One verification per test • Use assertions only in then block • Make them as expressive as possible assertEquals(2, flights.size()); assertTrue(flights.contains(flight1)); assertTrue(flights.contains(flight2)); Custom assertion: assertFlightsContainOnly(flights, flight1, flight2); Hamcerst: assertThat(flights, hasItems(flight1, flight2)); FEST-Assert: assertThat(flights).containsOnly(flight1, flight2);
  • 24. Simplify assertions • You don’t want to guess what you are expecting. It’s expectation anyway! assertEquals((a + b + c) / 3, average); • Loops are bad. int pos = 0; for (ToolGroup group: groups) { assertTrue(pos <= group.getLocation()); pos = group.getLocation(); }
  • 25. Simplify assertions • Never use conditionals! – You definately need a new example – ...or your example is broken
  • 26. Testing exceptions • It seems fine: @Test(expected=IllegalFlightNumberException.class) public void shouldFailForWrongFlightNumber() throws Exception { FlightManager flightManager = new FlightManager(); flightManager.addFlight(new Flight(10)); flightManager.addFlight(new Flight(15)); flightManager.getFlight(50); } • But what if new Flight() can throw same exception?
  • 28. How to make it work? • Train your people • Give them simple rules to adhere to (e.g. test template!) • Encourage pair programming • ...or at least code reviews • Do not listen to excuses – I don’t have time to write tests!
  • 29. Where to go next? • Online: – xunitpatterns.com – behavior-driven.org • Offline: – „xUnit Test Patterns” by Gerard Meszaros – „Growing Object-Oriented Software, Guided by Tests” by Steve Freeman, Nat Pryce – „Behavior Driven Development in Ruby with RSpec” by David Chelimsky, Aslak Hellesoy