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
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
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
• 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
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