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

Test-driven development with PHPUnit

Test-driven development with PHPUnit

Oliver Klee

August 04, 2023
Tweet

More Decks by Oliver Klee

Other Decks in Programming

Transcript

  1. About me Oliver „Oli“ Kle e #bon n #extension-de v

    #workshop-teache r #unit-testing-gu y #phpstan-gu y #best-practices-tea m #motivation-research-tea m #team-leadership-working-grou p #game-cookin g #powermetal
  2. The life cycle of a test new FooTest(); setUp(); /**

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

    method exercise method call verify assert…() tear down tearDown()
  4. Effects of TDD higher code coverage minimale 
 code think

    before you code tests now test what the code should do (instead of what it does) focused coding cleaner code structure
  5. The testing pyramid Unit Functional/
 Integration Acceptance Photo by Eugene

    Tkachenko on Unsplash: https://unsplash.com/photos/TF47p5PHW18
  6. 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