Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Test-driven development Patterns

Test-driven development Patterns

Davide Fucci

June 19, 2014
Tweet

More Decks by Davide Fucci

Other Decks in Programming

Transcript

  1. General Patterns § Isolated Test §  Should the running of the

    tests affect one another? § Test List §  What should you test? § Test First §  When should you write your tests? § Assert First §  When should you write your assert? § Test Data §  What data should you use in your test? § Evident Data §  How to represent intent?
  2. Green Bar Patterns § Fake it §  How to implement a

    broken test? § Triangulation §  How to abstract from tests? § Obvious implementation §  How to implement simple operations? § One-to-many §  How to implement operations on collections?
  3. Red Bar Patterns § One step test §  Which test to

    pick next? § Starter test §  Which test to start with? § Explanation test §  How do you explain the behaviour of your code? § Learning Test §  When to test for external software? § Another Test §  How to keep focused? § Break §  What to do when tired? § Do Over §  What to do when lost?
  4. Other *DD techniques § Acceptance Test-driven development (ATDD) §  Development driven

    by tests from the customer §  Set of Black-box tests §  Represents the features expected by the customer §  Reqs à Acceptance Tests à Implementation § Behviour Test-driven development (BDD) §  From low to high level requirements §  Focus on business values §  Use of user story-like templates §  (Semi) automatic tools transform them into tests
  5. Exercise Minesweeper is a cute little game. The goal of

    the game is to find all the mines within an NxM field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, take the following 4x4 field with 2 mines (which are represented by an * character): *... .... .*.. .... The same field, including the hint numbers described above, would look like this: *100 2210 1*10 1110 You should write a program that takes a field of NxM (0 < N,M <= 100) for input. Each safe square is represented by an "." character (without the quotes) and each mine square is represented by an "*" character (also without the quotes). You can decide how many mines (<NxM) there will be and where they will be in the field. The program should output N lines of M characters where the ”.” is replaced by the number of adiacent miles to that square. § To be implemented using Test-driven development