SlideShare a Scribd company logo
1 of 26
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-tests.svn.wordpress.org/trunk
• Base Plugin Setup
https://github.com/wp-cli/sample-plugin
or WP-CLI
http://wp-cli.org/
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:
1) svn co https://unit-tests.svn.wordpress.org/trunk wp-tests
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
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
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
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, Phone, Bio)
• Shortcode (For displaying employees)
• Template Tag (For displaying employees)
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H

More Related Content

What's hot

Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteFive Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteMediacurrent
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad WoodOrtus Solutions, Corp
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsQing-Cheng Li
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
Auditing Drupal Sites
Auditing Drupal SitesAuditing Drupal Sites
Auditing Drupal SitesExove
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialAlan Richardson
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with CodeceptionJeremy Coates
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Sam Becker
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Vijay Kumbhar
 
Javascript test frameworks
Javascript test frameworksJavascript test frameworks
Javascript test frameworkstalkitbr
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Cogapp
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in YiiIlPeach
 
High Performance JavaScript 2011
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011Nicholas Zakas
 

What's hot (20)

Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteFive Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Create, test, secure, repeat
Create, test, secure, repeatCreate, test, secure, repeat
Create, test, secure, repeat
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Auditing Drupal Sites
Auditing Drupal SitesAuditing Drupal Sites
Auditing Drupal Sites
 
Codeception
CodeceptionCodeception
Codeception
 
Integration Testing in Python
Integration Testing in PythonIntegration Testing in Python
Integration Testing in Python
 
Selenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver TutorialSelenium Clinic Eurostar 2012 WebDriver Tutorial
Selenium Clinic Eurostar 2012 WebDriver Tutorial
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with Codeception
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 
Drupal 7 ci and testing
Drupal 7 ci and testingDrupal 7 ci and testing
Drupal 7 ci and testing
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
Javascript test frameworks
Javascript test frameworksJavascript test frameworks
Javascript test frameworks
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
High Performance JavaScript 2011
High Performance JavaScript 2011High Performance JavaScript 2011
High Performance JavaScript 2011
 

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

How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.Matt Eland
 
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)Ozh
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
Getting started with PHPUnit
Getting started with PHPUnitGetting started with PHPUnit
Getting started with PHPUnitKhyati Gala
 
Frontend testing of (legacy) websites
Frontend testing of (legacy) websitesFrontend testing of (legacy) websites
Frontend testing of (legacy) websitesMichael Kubovic
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Extent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumExtent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumRaman Gowda Hullur
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battleAnand Ramdeo
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudCarlos Sanchez
 
Supermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talkSupermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talkMichael Peacock
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Mark Niebergall
 
15 Essential WordPress Plugins
15 Essential WordPress Plugins15 Essential WordPress Plugins
15 Essential WordPress PluginsMykl Roventine
 
Основы нагрузочного тестирования с инструментом Jmeter
Основы нагрузочного тестирования с инструментом JmeterОсновы нагрузочного тестирования с инструментом Jmeter
Основы нагрузочного тестирования с инструментом JmeterКомпьютерная школа Hillel
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressHarshad Mane
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012Abraham Aranguren
 

Similar to Unit testing plugins: The 5 W's and an H (20)

How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.
 
Test
TestTest
Test
 
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Getting started with PHPUnit
Getting started with PHPUnitGetting started with PHPUnit
Getting started with PHPUnit
 
Frontend testing of (legacy) websites
Frontend testing of (legacy) websitesFrontend testing of (legacy) websites
Frontend testing of (legacy) websites
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Extent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumExtent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/Selenium
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battle
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
 
Supermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talkSupermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talk
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
15 Essential WordPress Plugins
15 Essential WordPress Plugins15 Essential WordPress Plugins
15 Essential WordPress Plugins
 
Основы нагрузочного тестирования с инструментом Jmeter
Основы нагрузочного тестирования с инструментом JmeterОсновы нагрузочного тестирования с инструментом Jmeter
Основы нагрузочного тестирования с инструментом Jmeter
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012Introducing OWASP OWTF Workshop BruCon 2012
Introducing OWASP OWTF Workshop BruCon 2012
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

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

Editor's Notes

  1. Welcome to Plugin Unit Testing, The 5W’s and one H.Since I know many of you will feel the urge to tweet during this talk I encourage you to do so. In fact I’ve taken the liberty of suggesting a hashtag for this presentation. Feel free to use it.
  2. So let’s start with the first W, Who.
  3. I won’t bore you with the details of my life story but as far as my involvement with WordPress;How many of you had a blog on blogger?I began blogging in 2004 with a blogger blog and eventually wanted to have my own domain and more control. So in late 2007 / early 2008 I moved to self hosting and began using WordPress 2.3. My progression to WP developer mirrored that I think of most people at the time, I simply wanted to make changes to my theme and add features. Beginning there I transitioned that knowledge into building themes as a freelancer. I found out rather quickly that I hated trying to create designs, which was fortunate because I sucked at it. What I did love though was working on themes that allowed me to create unique functionality, or at least functionality that I hadn’t done before. That lead me into breaking down pieces of functionality into plugins and my eventual desire to do nothing but plugin development when it comes to WordPress. I eventually moved from freelancing to working for agencies and presently I work for The Nerdery as a PHP developer with a WordPress primary.
  4. The second W, What?
  5. So what are we going to talk about today. My hope, is that after you leave here today you’ll realize that unit testing can improve your plugin development, allow for easier upgrades when WordPress comes out with a new version, and overall just write better code.In order to make all the magic work we do have a few pre-requisites. Obviously since were unit testing we’ll need PHP Unit. The WordPress test suite so we can do our WordPress integration, and some extra files within our plugin that allows it to integrate with the test suite.The way you setup your testing environment is entirely up to you. One thing to keep in mind about the WordPress test suite, is that tests are written to work with trunk. This does not mean you have to use trunk when doing plugin testing, just be aware that if you attempt to run the WordPress core unit tests on an install other than trunk, you will often see failed tests. This is due to trunk having testable functions that may not be present in the stable public version. Since your plugin will be meant for use on the version you choose, this won’t be a problem as you won’t be using functions that aren’t available to you.The install and setup of the testing environment can be accomplished in two ways. Automated, and manually. If you are a WP-CLI user testing can be setup via command line that will both download the WordPress Test Suite and create a plugin template for your use.
  6. Moving onto the 3rd W, Where?
  7. So let’s dig in: Here is the make wordpress page that will help guide you in the setup of the core test suite. I’m not going to make you watch me setup the environment since it would take a while to download everything and configure but we can go through the commands for future reference.
  8. First we need to checkout the latest version of the test suite via svn and install it into a directory. In this case I’ve chosen “wp-tests”. You can name the directory whatever you’d like, this is just what I use.
  9. You don’t want to forget this next step. When the test suite is run it will expect a database to be setup with a specific set of data for comparison. You don’t want to wipe out what your doing so give the test suite it’s own database.This represents a departure from what would be considered normal PHP Unit Testing. Although a database can be used, a popular methodology uses mock objects to represent database data and run tests against it.For our WP test suite though, we’ll stick with what WordPress does and use the mysql database.
  10. The plugin testing skeleton is provided by the fine folks who gave us the wordpress command line utility. This github repo contains a copy of the output files generated by the command line tool for those times when you choose to go the manual setup route which were following here. This skeleton gives you everything you need to get yourself up and running. It includes the prerequisite bootstrap files, tests folder and gives us a nice structure. So let’s cover the config setup.
  11. TestsconfigBootstrap setup
  12. I personally don’t use WP-CLI in my workflow as it doesn’t fit our structure at work, but I’ve lifted the code from their website here.The first command will add the WordPress test suite and setup the configuration.Next you create a database for the test suite to use.
  13. The 4th W is When.When should we do unit testing of our plugins?
  14. How about Always?
  15. Ehh, maybe.So I’m going to have plenty of people in this room who will probably disagree with me on this point. And all of them will more than likely have valid arguments. But to be honest I’m more of a pragmatist when it comes to this and not so much of a purist. Do I think you should be doing it everytime, yes. Do I think it’s practical? No.Although I hope you can take some knowledge from this talk and incorporate it into your daily workflow, we all know that isn’t necessarily feasible. There are plenty of factors to consider, if your dealing with clients there is the budget issue vs. the complexity issue. The more complicated the functionality, the more likely you should be writing unit tests. The time it costs you on the front end writing the tests, will save you on the backend when you’d normally be troubleshooting bugs.If your writing the plugin for use in the WordPress repository, then you 100% should be writing tests for your code, there is no reason not to. In fact it would be nice if tests were required for submission to the repository so we wouldn’t run into the problem of plugins breaking, or uncertainty as to whether a wordpress version is supported.If your writing the plugin for a side project, or as a premium plugin, then yes 100% of the time, write tests.
  16. Code coverage comes into play as well. 100% coverage may not be needed depending on complexity, but I’m of the mindset that if you can, then you should.
  17. And the last W, why?Why do we write unit tests
  18. Easier bug fixingSo how are you currently testing your code if your not using unit tests?Do you have a testing script written out with steps to follow so all your features are covered?What’s that process look like, load the site in a browser, view the functionality in different scenarios and data sets?How long does that take?These are “almost” all questions you can eliminate via unit testing. With proper code coverage you can pinpoint the exact function call causing the problem and get it resolved quicker and retested much quicker than doing it the manual way. It only takes a few seconds to run a test, it might take you a half hour to step through a manual testing scenario.I’d suggest that whenever a new version of WordPress reaches the release candidate phase that you load it up and run your tests. Continue this with each itteration and when it’s launched as stable you’ll be confident in knowing that none of your users will have issues.
  19. Cleaner Code
  20. Maybe.I added the maybe to this one, because your bad coding habits are going to be your bad coding habits. There are plenty of benefits to thinking about your tests before you write any code at all. You can take a TDD or Test Driven Development approach and in fact write all of your tests before writing a single piece of actionable plugin code. Deciding whether to do this is personal choice. It’s perfectly fine to write the plugin and then go back and write tests as well. Whatever fits your mind set, is what you should do. One of the things that unit testing does bring into the forefront though is dependency injection. Making sure your functions are written as silos, where everything the function needs is passed into it. WordPress can make this difficult though. There are times you need to rely on globals, or perhaps your calling a WordPress function within your function that is going to give you some data. There are always going to be gotchas to think about.
  21. Architecture is something I think most coders struggle with. It seems that no matter how much planning you put into it, there always seems to be something that could be done better. I myself will sometimes fall into the trap where I believe I’ve got a good game plan in my head so I just jump right in and start coding. When this happens I always spend more time refactoring, or maybe missing a minor detail of the project scope where I then have to go back in and add it. If you go in with the mind set that you need to have your code test ready, you will find that you start considering things a bit more carefully.
  22. That brings us to the How,To use a real world example we’re going to work with a plugin that I wrote while working for a former employer about a year and a half, two years ago. We kept needing to have about us pages with employee bios listed and my go to solution was to use WordPress users and add images. Unfortunately the content people wanted greater flexibility and didn’t want to have to mess with using WordPress roles. So I came up with a simple plugin called Employees On Parade. That company has since closed it’s doors and I was given rights to take any code I’d written for my own use. I’ve been meaning to rewrite the plugin and put it in the repository but hadn’t gotten around to it. So here’s my opportunity.
  23. So what are the things we need to do, to make this plugin meet our goals.There is other functionality as well but for our purposes we’ll try to get through these before time runs out.