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

Test Drive Development with WordPress

Michael Cheng
September 05, 2012

Test Drive Development with WordPress

How to go about doing TDD with WordPress

Michael Cheng

September 05, 2012

More Decks by Michael Cheng

Other Decks in Programming


  1. What is TDD? • Getting into the habit of writing

    tests before writing code. • TDD are continuous short cycle of test, code, refactor. • Test cases are in separate files. No more print_r & var_dump in your code! • The tests contain assertions that are either true or false. Passing the tests confirms correct behavior of the code. 2
  2. 3

  3. Why TDD? • TDD gives you higher confidence that your

    code is doing what it's suppose to. • Small wins makes the coding process more enjoyable (Gamification). • Working code every step of the way! 4
  4. TDD Process 1 Feature specifications 2 Write test cases 3

    Tests will fail 4 Write code to pass the tests (minimal) 5 Pass all tests 6 Refactor "Make it green, then make it clean" 5
  5. • PHPUnit is the de-facto standard for unit testing in

    PHP projects. It provides both a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results. • http://phpunit.de • Created by Sebastian Bergmann 6
  6. WordPress Unit Tests • Core libraries unit tests • http://unit-tests.trac.wordpress.org/wiki

    • Plugins Development • Nikolay Bachiyski (https://github.com/nb/wordpress- tests) • Themes Development • http://codex.wordpress.org/Theme_Unit_Test 7
  7. WordPress Unit Tests • Nikolay Bachiyski • https://github.com/nb/ wordpress-tests •

    http://wordpress.tv/ 2011/08/20/nikolay- bachiyski-unit-testing-will- change-your-life/ 8