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

Test-driven development with PHPUnit

Test-driven development with PHPUnit

610644ae9328059c33a272d08b90c75d?s=128

Oliver Klee

August 05, 2022
Tweet

More Decks by Oliver Klee

Other Decks in Programming

Transcript

  1. Test-driven 
 development 
 with PHPUnit Oliver Klee, 2022-08 @oliklee

    | Mastodon: oliklee@chaos.socail | typo3-coding@oliverklee.de
  2. About me Oliver „Oli“ Klee #bonn #extension-dev #workshop-teacher #unit-testing-guy #phpstan-guy

    #typo3-ombudsperson #typo3-quality-assurance-initiative #gami fi cation-working-group #game-cooking #powermetal
  3. ???

  4. The goals ✓ You have a clearer understanding on how

    TDD works. ✓(optional) You get test-infected. ✓You learn at least 1 new testing pattern. ✓We all have fun.
  5. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback
  6. The rules 1. There are no stupid questions. 2. The

    joker rule.
  7. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback
  8. Unit
 Tests?

  9. Manual testing is cumbersome

  10. Automated
 testing 
 is fast

  11. Unit tests for the 
 TYPO3 Core

  12. Unit Tests
 406 (144) tests/s

  13. Functional Tests
 8.13 (1.97) tests/s

  14. Acceptance Tests
 .009 (.003) tests/s

  15. Verify that your code does what you expect

  16. Make sure that 
 your changes won‘t
 break anything

  17. Keep others 
 from breaking your code

  18. Don’t break anything 
 even in complex 
 projects

  19. Create a safety net for refactoring or for 
 TYPO3

    updates
  20. Improve the structure of your code

  21. Find the location of bugs

  22. Green feels good!

  23. Let’s get
 some terms
 straight

  24. The two programming modes clean hacky

  25. Testsuite Testcase Test Assertion Test Test Testcase

  26. The life cycle of a test new FooTest(); setUp(); /**

    @test */ lifeIsGood(); tearDown();
  27. Code test-first write
 test write
 code refactor

  28. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback
  29. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback
  30. https://github.com/TYPO3-Documentation/tea/ Branch: workshop/t3dd22 File: Exercises.md

  31. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback
  32. Naming
 Tests

  33. Use meaningful test names classCanBeInstantiated setTitleSetsTitle setSizeWithZeroThrowsException hasTitleForEmptyTitleReturnsFalse Name the

    behavior. Name the preconditions. Name the method. Don’t use 
 “works” or 
 “works correctly”. measureFrubbleWorksCorrectly
  34. The travel plan 1. getting starte d 2. concepts &

    term s 3. testing pattern s 4. hands-o n 5. naming test s 6. hands-o n 7. ending & feedback