Pro Yearly is on sale from $80 to $50! »

Test-driven development with PHPUnit

Test-driven development with PHPUnit

610644ae9328059c33a272d08b90c75d?s=128

Oliver Klee

June 23, 2018
Tweet

Transcript

  1. Test-driven 
 Development
 with PHPUnit Oliver Klee, 2018-06 @oliklee typo3-coding@oliverklee.de

  2. This is Oliver Klee (me!) Workshop teacher •unit testing •extension

    development •software quality •saying „no“, consent culture TYPO3 extension
 developer (wanna-be)
 singer @oliklee oliverklee oliverklee.de
  3. unterstand TDD become test-infected have fun Workshop goals

  4. Workshop Rules

  5. Stand up
 for your tests

  6. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  7. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  8. Unit
 Tests?

  9. Manual testing is cumbersome

  10. Automated
 testing
 is fast

  11. Unit tests for the
 TYPO3 Core

  12. > 4400 tests

  13. < 14 seconds

  14. Verify that your code does what you expect

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

  16. Keep others
 from breaking your code

  17. Don’t break anything
 even in complex
 projects

  18. Create a safety net for refactoring or for
 TYPO3 updates

  19. Improve the structure of your code

  20. Green feels good!

  21. https://github.com/oliverklee/tdd-reader
 /Exercises/tdd-exercises-en.md

  22. Let’s get
 some terms
 straight

  23. The two programming modes clean hacky

  24. Testsuite Testcase Test Assertion Test Test Testcase

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

    @test */ lifeIsGood(); tearDown();
  26. 4 test phases set up setUp()
 code in the test

    method exercise method call verify assert…() tear down tearDown()
  27. Code test-first write
 test write
 code refactor

  28. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  29. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  30. None
  31. https://github.com/oliverklee/tdd-reader
 /Exercises/tdd-exercises-en.md

  32. Test levels http://filipdefar.com/2015/06/tested-be-thy-name.html

  33. Unit tests are small and fast

  34. Integration tests test how components work together in TYPO3:
 „functional

    tests“
  35. Systemtests test the big picture

  36. Test types

  37. Blackbox tests test the public API

  38. Whitebox tests inner workings test the

  39. Functional
 tests

  40. Acceptance tests Selenium Codeception

  41. Anti-
 zombie tests-

  42. Regression tests

  43. Smoke tests

  44. Smoke tests

  45. Story tests for Behavior-driven development (BDD) Behat Codeception

  46. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  47. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  48. Naming
 Tests

  49. 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
  50. None
  51. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  52. Workshop roadmap 1. Terms & concepts 2. Testing patterns 3.

    Naming things 4. Code katas
  53. None