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

TDD sucks, but that does not have to be.

TDD sucks, but that does not have to be.

TDD is easy to learn but hard to master. Often beginners end up in mess when using TDD in their projects and then blame this method. This presentation shows the top 5 pitfalls when starting with TDD and how you can avoid them.

Christian Fischer

September 26, 2019
Tweet

More Decks by Christian Fischer

Other Decks in Programming

Transcript

  1. Design Evolution Test make my Design hard to change. When

    the Design changes due to new requirements, I have to change my tests everytime.
  2. QueryParserTest Design Evolution „guitar“ -> [guitar] “red electric guitar“ ->

    [red, electric, guitar] „red guitar with gigbag“ -> [red,guitar,gigback] „red guitar and gigbag“ -> [red,guitar,gigback] QueryParser + parse(String query): String[] - removeStopwords(String[] words) : String[] „red guitar with 7 gigbag“ -> [red,guitar,gigback] - removeNumbers(String[] words) : String[]
  3. QueryFilter QueryFilterTest QueryParserTest Design Evolution „guitar“ -> [guitar] “red electric

    guitar“ -> [red, electric, guitar] [red,guitar,with,gigback]-> [red,guitar,gigback] [red,guitar,and,gigback] -> [red,guitar,gigback] QueryParser + parse(query: String): String [] - removeStopwords(words: String[]) : String[] [red,guitar,7,gigback] -> [red,guitar,gigback] - removeNumbers(words: String[]) : String[] + filter(words: String[]): String[] + QueryParser(filter: QueryFilter) -setUpMocks / MockInteractionTest
  4. QueryFilter QueryFilterTest QueryParserTest Design Evolution „guitar“ -> [guitar] “red electric

    guitar“ -> [red, electric, guitar] [red,guitar,with,gigback]-> [red,guitar,gigback] [red,guitar,and,gigback] -> [red,guitar,gigback] QueryParser + parse(query: String) - removeStopwords(words: String[]) : String[] [red,guitar,7,gigback] -> [red,guitar,gigback] - removeNumbers(words: String[]) : String[] + filter(words: String[]): String[] + QueryParser(filter: QueryParser) -setUpMocks „Guitar“ -> [guitar] - toLowerCase(word: String) : String - toSingular(word: String) : String “guitars“ -> [guitar]
  5. QueryFilter QueryFilterTest QueryParserTest Design Evolution „guitar“ -> [guitar] “red electric

    guitar“ -> [red, electric, guitar] [red,guitar,with,gigback]-> [red,guitar,gigback] [red,guitar,and,gigback] -> [red,guitar,gigback] QueryParser + parse(query: String) - removeStopwords(words: String[]) : String[] [red,guitar,7,gigback] -> [red,guitar,gigback] - removeNumbers(words: String[]) : String[] + filter(words: String[]): String[] + QueryParser(filter: QueryFilter, normalizer: QueryNormalizer) -setUpMocks / MockInteractionTest QueryNormalizerTest „Guitar“ -> „guitar“ „guitars“ -> „guitar“ QueryNormalizer + normalize(word: String): String - toLowerCase(word: String) : String - toSingular(word: String) : String
  6. Strong Coupling Parser Module QueryParser QueryFilter QueryNormalizer QueryParserTest Parser Tests

    QueryFilterTest QueryNormalizerTest public Class package private Class
  7. Loose Coupling Parser Module QueryParser QueryFilter QueryNormalizer QueryParserTest Parser Tests

    QueryFilterTest QueryNormalizerTest public Class package private Class
  8. Weak Unit Tests I feel like I am writing code

    just for the sake of Code Coverage.
  9. Weak Unit Tests Does the Endpoint has the corrrect Path

    & Method? Does the Deserialization works as expected? Does the Serialization works as expected?
  10. Test Fixture Order Repository setUp Data MyShop <<Spring Boot Application>>

    Order REST Controller Order Mgmt RestAssured DBUnit ShopTest send/verify Request
  11. Test Pyramid Order Repository setUp Data MyShop <<Spring Boot Application>>

    Order REST Controller Order Mgmt RestAssured DBUnit ShopTest send/verify Request 5 5 5 1
  12. 5 Rules for efficient and effective TDD 1 Develop your

    Tests against the Module API. 2 Test the Behaviour, not the Implementation. 4 Use Integration Tests for I/O-Components. 3 Don‘t mock external libraries, use Adapters. 5 Make use of the Test Pyramid.
  13. no Multi- Tasking Protection from Overengineering Complexity Partitioning no Fear

    of Change zero Debug Time Testable Design TDD Benefits TDD