Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Plugin Unit Testing
The 5 W’s and one H
Tweet?
#omgunittestingforwordpressismindbogglingeas
yandwhenigethomeiwillincorporateitintomyexist
ingworkflow
WHO?
Tom Jenkins
@techguytom
tdjenkins
techguytom
WHAT?
Unit Testing a plugin?
• PHP Unit
https://github.com/sebastianbergmann/phpunit/
• WordPress Test Suite
https://unit-...
WHERE?
Test Suite Requirements:
http://make.wordpress.org/core/handbook/automated-testing/
WHERE?
Test Suite Requirements:
http://make.wordpress.org/core/handbook/automated-testing/
From a directory of your choice...
WHERE?
Test Suite Requirements:
http://make.wordpress.org/core/handbook/automated-testing/
From a directory of your choice...
WHERE?
Test Suite Requirements:
http://make.wordpress.org/core/handbook/automated-testing/
From a directory of your choice...
WHERE?
WP-CLI
# Initialize the testing library
wp core init-tests ~/svn/wp-tests --dbname=wp_test --dbuser=root --
dbpass=...
WHEN?
Always?!?
WHEN?
Always?!?
Ehh, maybe
WHEN?
Code Coverage
Do we need 100%?
WHY?
• Easier bug fixing
WHY?
• Easier bug fixing
• Cleaner code
WHY?
• Easier bug fixing
• Cleaner code, maybe?
WHY?
• Easier bug fixing
• Cleaner code, maybe?
• Better Architecture
HOW?
Employees On Parade
• Custom Post Type (Employee)
• Custom Taxonomy (Departments)
• Custom Meta Fields (Title, Email,...
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
Upcoming SlideShare
Loading in …5
×

Unit testing plugins: The 5 W's and an H

3,315 views

Published on

WordCamp Chicago 2013 presentation

Published in: Technology, Business
  • Be the first to comment

Unit testing plugins: The 5 W's and an H

  1. 1. Plugin Unit Testing The 5 W’s and one H
  2. 2. Tweet? #omgunittestingforwordpressismindbogglingeas yandwhenigethomeiwillincorporateitintomyexist ingworkflow
  3. 3. WHO? Tom Jenkins @techguytom tdjenkins techguytom
  4. 4. WHAT? Unit Testing a plugin? • PHP Unit https://github.com/sebastianbergmann/phpunit/ • WordPress Test Suite https://unit-tests.svn.wordpress.org/trunk • Base Plugin Setup https://github.com/wp-cli/sample-plugin or WP-CLI http://wp-cli.org/
  5. 5. WHERE? Test Suite Requirements: http://make.wordpress.org/core/handbook/automated-testing/
  6. 6. WHERE? Test Suite Requirements: http://make.wordpress.org/core/handbook/automated-testing/ From a directory of your choice: 1) svn co https://unit-tests.svn.wordpress.org/trunk wp-tests
  7. 7. WHERE? Test Suite Requirements: http://make.wordpress.org/core/handbook/automated-testing/ From a directory of your choice: 1) svn co https://unit-tests.svn.wordpress.org/trunk wp-tests 2) Create a new MYSQL database
  8. 8. WHERE? Test Suite Requirements: http://make.wordpress.org/core/handbook/automated-testing/ From a directory of your choice: 1) svn co https://unit-tests.svn.wordpress.org/trunk wp-tests 2) Create a new MYSQL database 3) Add the plugin testing skeletonhttps://github.com/wp- cli/sample-plugin
  9. 9. WHERE? WP-CLI # Initialize the testing library wp core init-tests ~/svn/wp-tests --dbname=wp_test --dbuser=root -- dbpass=asd mysql -u'root' -p'asd' -e 'CREATE DATABASE IF NOT EXISTS wp_test' # Generate the plugin files wp scaffold plugin sample-plugin # Run the tests cd wp-content/plugins/sample-plugin WP_TESTS_DIR=~/svn/wp-tests phpunit
  10. 10. WHEN? Always?!?
  11. 11. WHEN? Always?!? Ehh, maybe
  12. 12. WHEN? Code Coverage Do we need 100%?
  13. 13. WHY? • Easier bug fixing
  14. 14. WHY? • Easier bug fixing • Cleaner code
  15. 15. WHY? • Easier bug fixing • Cleaner code, maybe?
  16. 16. WHY? • Easier bug fixing • Cleaner code, maybe? • Better Architecture
  17. 17. HOW? Employees On Parade • Custom Post Type (Employee) • Custom Taxonomy (Departments) • Custom Meta Fields (Title, Email, Phone, Bio) • Shortcode (For displaying employees) • Template Tag (For displaying employees)

×