Slide 1

Slide 1 text

The secret to coding with confidence Test Driven Development with WordPress 1

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

• 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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Demo 9

Slide 10

Slide 10 text

Demo Script • Installing PHPUnit. • Checkout unit tests • Sample Unit Test for a WP Plugin. 10

Slide 11

Slide 11 text

Installing PHPUnit # pear config-set auto_discover 1 # pear install pear.phpunit.de/PHPUnit 11

Slide 12

Slide 12 text

Sample Code https://github.com/miccheng/WordPress-TDD 12

Slide 13

Slide 13 text

End of File 13