Effizientere WordPress-Plugin-Entwicklung mit Softwaretests

DECK36
DECK36DECK36
Effizientere
WordPress-Plugin-Entwicklung mit
Softwaretests
Martin Schütte
About DECK36
• Small team of 7 engineers
• Longstanding expertise in designing, implementing and operating
complex web systems
• Developing own data intelligence-focused tools and web services
• Offering our expert knowledge in Automation & Operation,
Architecture & Engineering, Analytics & Data Logistics
1. Dev & Test Environments
2. Testing Variants
Static Code Analysis
Unit Testing
Integration Testing
Behaviour Testing
3. Integration & Automation
Main Questions
How can I know (my) software is correct?
How does my boss know software is correct?
How do I know software implements a given design?
How can we discuss what “correct” is, anyway?
We always need:
• implicit assumptions,
• explicit specifications.
Levels of Testing
..
abstract
.
specific
.
Unit Tests
.
Integration Tests
.
Acceptance
Tests
Example Plugin: Freifunkmeta
Use a Dev
Environment
Vagrant
Configuration tool for (VirtualBox) VM
setup and provisioning.
“Local cloud”
• Self service
• Instant provisioning
Useful for development
• reproducible environment
• independent PHP 5.x setups
• try things and not jeopardise
your dev environment
VagrantPress
$ git clone https://github.com/chad-thompson/vagrantpress.git
$ cd vagrantpress
$ vagrant up
will setup VM with:
• Ubuntu Precise (12.04), Apache 2.2, MySQL 5.5, PHP 5.3
• Wordpress 3.8
• phpMyAdmin
• PHPUnit
• phpcs, phploc, phpdepend, …
Testing Variants
Coding Style
$ phpcs --standard=WordPress freifunkmeta.php
FILE: [...]/plugins/freifunkmeta/freifunkmeta.php
---------------------------------------------------------------------
FOUND 360 ERROR(S) AND 406 WARNING(S) AFFECTING 338 LINE(S)
---------------------------------------------------------------------
21 | ERROR | Incorrect indentation; expected 1 space, found 4
22 | WARNING | Line is indented with space not tab
33 | ERROR | String "Unable to retrieve URL %s, error: %s" does
| | not require double quotes; use single quotes instead
322 | ERROR | Closing parenthesis of a multi-line function
| | definition must be on a line by itself
440 | ERROR | Expected next thing to be a escaping function,
| | not '"<option value='$city' $selected>$prettycity
| | </option>"'
Code Metrics
$ php pdepend_summary.php freifunkmeta.php
Package/Class Method LoC %Comment CCN NPath
------------- ------ --- -------- --- -----
FF_Meta output_ff_contact 49 6.1 10 384
FF_Meta shortcode_handler 41 2.4 9 48
FF_Community __construct 12 0.0 7 15625
FF_Meta register_stuff 18 0.0 5 16
FF_Meta aux_get_all_locations 23 8.7 5 6
FF_Community make_from_city 15 0.0 4 20
[...]
Example Plugin: Freifunkmeta
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
Unit Testing
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
Simple PHPUnit Test Case
class LowLevelTests extends PHPUnit_Framework_TestCase {
function setUp() {
$this->FFM = new FF_Meta();
}
function test_output_ff_state() {
$data = array("state" => array("nodes" => 429));
$ret = $this->FFM->output_ff_state($data);
$this->assertRegExp('/429/', $ret);
}
}
Unit Testing (contd.)
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
Integration Testing
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
Unit Testing with Mock Object
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
Example: Test with Dependency Injection
class MockDataService {
function get($url) {
return $some_fixed_data;
}
}
class WpIntegrationTests extends WP_UnitTestCase {
function setUp() {
parent::setUp();
// get plugin instance and replace ext. data service:
$this->plugin = $GLOBALS['wp-plugin-ffmeta'];
$this->plugin->reset_external_data_service(
new MockDataService() );
}
// ...
Example: Test with Dependency Injection
// ...
function test_post_ff_services() {
$post_attribs = array(
'post_title' => 'Test',
'post_content' => '[ff_services]' );
$post = $this->factory->post->create_and_get(
$post_attribs );
// w/o filter:
$this->assertEquals($post_content, $post->post_content);
// with filter:
$output = apply_filters( 'the_content',
$post->post_content );
$this->assertRegExp('/radio.ffhh/', $output);
}
}
PHPUnit Output
Behaviour Testing
..WP Blog.
FF_Meta
.
WP Core
.
Other Plugins
.
FF_Community
.
FF_Dir
.
Output
Formatter
.
HTTP Get
Service
WordPress Shortcode Plugin Test
..
Feature: Use Shortcodes
In order to use my Plugin
As a website author
I need to write posts with shortcodes
Background:
Given I am logged in as "admin" with "vagrant"
Scenario: Without the plugin
Given the plugin "freifunkmeta" is "inactive"
When I write a post with title "test" and content "[ff_contact]"
Then I should see "ff_contact"
Scenario: With the plugin
Given the plugin "freifunkmeta" is "active"
When I write a post with title "test" and content "[ff_contact]"
Then I should see "Twitter" in the ".ff_contact" element
And I should not see "ff_contact"
Behat Output
Implementation / Translation
A look behind the curtain:
• framework is clever but not magical
• some translation needed
• statements have to become executable code
Mechanism:
• plain sentence → method name
• quoted words → arguments
• matching with annotated regular expressions
• methods yield success, exception, or pending exception
Example: Behat Context (PHP)
/**
* from MinkContext
* Checks, that page contains specified text.
*
* @Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)"$/
*/
public function assertPageContainsText($text)
{
$this->assertSession()->pageTextContains(
$this->fixStepArgument($text));
}
The Big Picture
..Features.
Step Definitions
.
WebDriver
.
Browser
The Big Picture
..Features.
Behat (PHP)
.
cucumber.js
.
Cucumber
(Ruby)
.
PhantomJS
.
Goutte
.
Selenium
.
Firefox
.
Chrome
Unit & Behaviour Testing
Unit Tests
• unit testing
• programmers
• programming language
• bottom-up
• assertXYZ
• tests derived from user stories
⇒ development tool
Behaviour Tests
• acceptance test scenarios
• non-developers
• language of business domain
• top-down / outside-in
• X should do Y
• execute user stories
⇒ design & communication tool
Automate!
Scripting
Basis for all automation.
Lots of useful builtins and packages:
• wp core download/install/config/…
• wp export/import
• wp plugin get/install/update/…
• wp scaffold _s/plugin/plugin-tests
• wp server
wp scaffold
Generate skeleton code for a new plugin & unit tests:
$ cd wordpress/wp-content/plugins
$ wp scaffold plugin-tests awesome
$ find awesome
awesome/
awesome/awesome.php
awesome/bin
awesome/bin/install-wp-tests.sh
awesome/tests
awesome/tests/bootstrap.php
awesome/tests/test-sample.php
awesome/.travis.yml
awesome/phpunit.xml
wp scaffold (contd.)
Create WP instance and run unit tests:
$ cd awesome
$ bash ./bin/install-wp-tests.sh wp_tests root vagrant latest
...
$ phpunit
PHPUnit 4.0.17 by Sebastian Bergmann.
[...]
Configuration read from [...]/plugins/awesome/phpunit.xml
.
Time: 5.52 seconds, Memory: 23.50Mb
OK (1 test, 1 assertion)
Version Control
• use version control!
• many possible workflows,
e. g. branches for dev and release
• use pre-commit hooks,
e. g. with php -l syntax check
Travis-CI
Continuous Integration service for GitHub
1. gets notified on push
2. builds project
3. runs phpunit
4. summarizes results,
alert on failure
Example .travis.yml
language: php
php:
- 5.4
- 5.5
- hhvm
env:
- WP_VERSION=3.8.3
- WP_VERSION=latest
before_script:
- bash bin/install-wp-tests.sh wordpress_test 
root '' localhost $WP_VERSION
script: phpunit
Travis-CI Pass
Automated Testing
Target: no manual effort.
Continuous Integration:
• frequent code check-ins
• verified by automated
builds and tests
• quickly find bugs
and regressions
Continuous Deployment:
• (semi-)automated deployment
• plan for rollback
Costs and Benefits of Testing
• Testing (like Documentation) has a cost
• usually: productivity improvement > cost
• but find the right balance
Conclusion
I get paid for code that works, not for tests, so my philosophy is to test
as little as possible to reach a given level of confidence.
– Kent Beck
Links
• http://phpqatools.org/: PHP Quality Assurance Toolchain
• http://wpgear.org/: compendium of useful WP developer tools
• http://wptest.io/: test data for WP plugins and themes
• Ptah Dunbar: Automated Testing in WordPress, Really?!
• tuts+ articles by Tom McFarlin
• Conversation “Is TDD Dead?”
Thank You
1 of 41

Recommended

Tp install anything by
Tp install anythingTp install anything
Tp install anythingAlessandro Franceschi
1.6K views20 slides
Running trusted payloads with Nomad and Waypoint by
Running trusted payloads with Nomad and WaypointRunning trusted payloads with Nomad and Waypoint
Running trusted payloads with Nomad and WaypointBram Vogelaar
144 views26 slides
Comprehensive Terraform Training by
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
23K views148 slides
Infrastructure as Code with Terraform by
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with TerraformTim Berry
3.7K views46 slides
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008) by
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Tim Bunce
1K views72 slides
Regex Considered Harmful: Use Rosie Pattern Language Instead by
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadAll Things Open
1K views38 slides

More Related Content

What's hot

Testing Wi-Fi with OSS Tools by
Testing Wi-Fi with OSS ToolsTesting Wi-Fi with OSS Tools
Testing Wi-Fi with OSS ToolsAll Things Open
414 views31 slides
Supercharging Content Delivery with Varnish by
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSamantha Quiñones
6.2K views110 slides
Puppet and the HashiCorp Suite by
Puppet and the HashiCorp SuitePuppet and the HashiCorp Suite
Puppet and the HashiCorp SuiteBram Vogelaar
285 views55 slides
Reusable, composable, battle-tested Terraform modules by
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesYevgeniy Brikman
28.4K views150 slides
Perl Dist::Surveyor 2011 by
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011Tim Bunce
2.7K views24 slides
Network Automation: Ansible 101 by
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101APNIC
1.8K views54 slides

What's hot(20)

Supercharging Content Delivery with Varnish by Samantha Quiñones
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
Samantha Quiñones6.2K views
Puppet and the HashiCorp Suite by Bram Vogelaar
Puppet and the HashiCorp SuitePuppet and the HashiCorp Suite
Puppet and the HashiCorp Suite
Bram Vogelaar285 views
Reusable, composable, battle-tested Terraform modules by Yevgeniy Brikman
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
Yevgeniy Brikman28.4K views
Perl Dist::Surveyor 2011 by Tim Bunce
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011
Tim Bunce2.7K views
Network Automation: Ansible 101 by APNIC
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101
APNIC1.8K views
Making Your Capistrano Recipe Book by Tim Riley
Making Your Capistrano Recipe BookMaking Your Capistrano Recipe Book
Making Your Capistrano Recipe Book
Tim Riley6.8K views
Fluentd and PHP by chobi e
Fluentd and PHPFluentd and PHP
Fluentd and PHP
chobi e5.8K views
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson... by Puppet
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Puppet169 views
Terraform Modules and Continuous Deployment by Zane Williamson
Terraform Modules and Continuous DeploymentTerraform Modules and Continuous Deployment
Terraform Modules and Continuous Deployment
Zane Williamson1.9K views
Python Deployment with Fabric by andymccurdy
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
andymccurdy34K views
Ansible 實戰:top down 觀點 by William Yeh
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
William Yeh19.6K views
Puppet for dummies - ZendCon 2011 Edition by Joshua Thijssen
Puppet for dummies - ZendCon 2011 EditionPuppet for dummies - ZendCon 2011 Edition
Puppet for dummies - ZendCon 2011 Edition
Joshua Thijssen13K views
Fluentd v0.14 Plugin API Details by SATOSHI TAGOMORI
Fluentd v0.14 Plugin API DetailsFluentd v0.14 Plugin API Details
Fluentd v0.14 Plugin API Details
SATOSHI TAGOMORI21.6K views
Configuration Surgery with Augeas by Puppet
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
Puppet12.7K views
Fluentd at HKOScon by N Masahiro
Fluentd at HKOSconFluentd at HKOScon
Fluentd at HKOScon
N Masahiro1.4K views
Pwning with powershell by jaredhaight
Pwning with powershellPwning with powershell
Pwning with powershell
jaredhaight2.1K views
Terraform in deployment pipeline by Anton Babenko
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
Anton Babenko2.9K views
Writing Ansible Modules (CLT'19) by Martin Schütte
Writing Ansible Modules (CLT'19)Writing Ansible Modules (CLT'19)
Writing Ansible Modules (CLT'19)
Martin Schütte1.3K views

Similar to Effizientere WordPress-Plugin-Entwicklung mit Softwaretests

Creating a Smooth Development Workflow for High-Quality Modular Open-Source P... by
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Pantheon
1.1K views85 slides
Simplify your professional web development with symfony by
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
2.7K views40 slides
Release with confidence by
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
1.8K views35 slides
Advanced Eclipse Workshop (held at IPC2010 -spring edition-) by
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Bastian Feder
1.5K views46 slides
Assurer - a pluggable server testing/monitoring framework by
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkGosuke Miyashita
1.8K views78 slides
Integration Testing with Behat drupal by
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupalOscar Merida
407 views12 slides

Similar to Effizientere WordPress-Plugin-Entwicklung mit Softwaretests(20)

Creating a Smooth Development Workflow for High-Quality Modular Open-Source P... by Pantheon
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Pantheon1.1K views
Simplify your professional web development with symfony by Francois Zaninotto
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
Francois Zaninotto2.7K views
Release with confidence by John Congdon
Release with confidenceRelease with confidence
Release with confidence
John Congdon1.8K views
Advanced Eclipse Workshop (held at IPC2010 -spring edition-) by Bastian Feder
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder1.5K views
Assurer - a pluggable server testing/monitoring framework by Gosuke Miyashita
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita1.8K views
Integration Testing with Behat drupal by Oscar Merida
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
Oscar Merida407 views
Behavior & Specification Driven Development in PHP - #OpenWest by Joshua Warren
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren1.4K views
All the Laravel things: up and running to making $$ by Joe Ferguson
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
Joe Ferguson829 views
Lean Php Presentation by Alan Pinstein
Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein13.7K views
PHP North-East - Automated Deployment by Michael Peacock
PHP North-East - Automated DeploymentPHP North-East - Automated Deployment
PHP North-East - Automated Deployment
Michael Peacock496 views
Automated Deployment by phpne
Automated DeploymentAutomated Deployment
Automated Deployment
phpne1.4K views
Performance and Scalability Testing with Python and Multi-Mechanize by coreygoldberg
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg9.6K views
Profiling PHP with Xdebug / Webgrind by Sam Keen
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
Sam Keen43.8K views
Windows Server AppFabric Caching - What it is & when you should use it? by Robert MacLean
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?
Robert MacLean2.6K views
Php through the eyes of a hoster by Combell NV
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hoster
Combell NV1.2K views
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e... by Anupam Ranku
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Anupam Ranku791 views
IDE and Toolset For Magento Development by Abid Malik
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
Abid Malik238 views
Simple tools to fight bigger quality battle by Anand Ramdeo
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battle
Anand Ramdeo2.6K views
Php through the eyes of a hoster phpbnl11 by Combell NV
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
Combell NV6.5K views

More from DECK36

Our Puppet Story (GUUG FFG 2015) by
Our Puppet Story (GUUG FFG 2015)Our Puppet Story (GUUG FFG 2015)
Our Puppet Story (GUUG FFG 2015)DECK36
1.2K views67 slides
PHP Backends for Real-Time User Interaction using Apache Storm. by
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.DECK36
4K views84 slides
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto... by
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...DECK36
6.1K views30 slides
Our Puppet Story (Linuxtag 2014) by
Our Puppet Story (Linuxtag 2014)Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)DECK36
2.9K views49 slides
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014) by
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)DECK36
1.7K views47 slides
Hyperdex - A closer look by
Hyperdex - A closer lookHyperdex - A closer look
Hyperdex - A closer lookDECK36
4.4K views38 slides

More from DECK36(7)

Our Puppet Story (GUUG FFG 2015) by DECK36
Our Puppet Story (GUUG FFG 2015)Our Puppet Story (GUUG FFG 2015)
Our Puppet Story (GUUG FFG 2015)
DECK361.2K views
PHP Backends for Real-Time User Interaction using Apache Storm. by DECK36
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.
DECK364K views
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto... by DECK36
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
DECK366.1K views
Our Puppet Story (Linuxtag 2014) by DECK36
Our Puppet Story (Linuxtag 2014)Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)
DECK362.9K views
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014) by DECK36
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
DECK361.7K views
Hyperdex - A closer look by DECK36
Hyperdex - A closer lookHyperdex - A closer look
Hyperdex - A closer look
DECK364.4K views
Log everything! @DC13 by DECK36
Log everything! @DC13Log everything! @DC13
Log everything! @DC13
DECK36905 views

Recently uploaded

Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeNUS-ISS
19 views47 slides
RADIUS-Omnichannel Interaction System by
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction SystemRADIUS
15 views21 slides
Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
34 views40 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
209 views20 slides
Black and White Modern Science Presentation.pptx by
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 slides
[2023] Putting the R! in R&D.pdf by
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdfEleanor McHugh
38 views127 slides

Recently uploaded(20)

Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views

Effizientere WordPress-Plugin-Entwicklung mit Softwaretests

  • 2. About DECK36 • Small team of 7 engineers • Longstanding expertise in designing, implementing and operating complex web systems • Developing own data intelligence-focused tools and web services • Offering our expert knowledge in Automation & Operation, Architecture & Engineering, Analytics & Data Logistics
  • 3. 1. Dev & Test Environments 2. Testing Variants Static Code Analysis Unit Testing Integration Testing Behaviour Testing 3. Integration & Automation
  • 4. Main Questions How can I know (my) software is correct? How does my boss know software is correct? How do I know software implements a given design? How can we discuss what “correct” is, anyway? We always need: • implicit assumptions, • explicit specifications.
  • 5. Levels of Testing .. abstract . specific . Unit Tests . Integration Tests . Acceptance Tests
  • 8. Vagrant Configuration tool for (VirtualBox) VM setup and provisioning. “Local cloud” • Self service • Instant provisioning Useful for development • reproducible environment • independent PHP 5.x setups • try things and not jeopardise your dev environment
  • 9. VagrantPress $ git clone https://github.com/chad-thompson/vagrantpress.git $ cd vagrantpress $ vagrant up will setup VM with: • Ubuntu Precise (12.04), Apache 2.2, MySQL 5.5, PHP 5.3 • Wordpress 3.8 • phpMyAdmin • PHPUnit • phpcs, phploc, phpdepend, …
  • 11. Coding Style $ phpcs --standard=WordPress freifunkmeta.php FILE: [...]/plugins/freifunkmeta/freifunkmeta.php --------------------------------------------------------------------- FOUND 360 ERROR(S) AND 406 WARNING(S) AFFECTING 338 LINE(S) --------------------------------------------------------------------- 21 | ERROR | Incorrect indentation; expected 1 space, found 4 22 | WARNING | Line is indented with space not tab 33 | ERROR | String "Unable to retrieve URL %s, error: %s" does | | not require double quotes; use single quotes instead 322 | ERROR | Closing parenthesis of a multi-line function | | definition must be on a line by itself 440 | ERROR | Expected next thing to be a escaping function, | | not '"<option value='$city' $selected>$prettycity | | </option>"'
  • 12. Code Metrics $ php pdepend_summary.php freifunkmeta.php Package/Class Method LoC %Comment CCN NPath ------------- ------ --- -------- --- ----- FF_Meta output_ff_contact 49 6.1 10 384 FF_Meta shortcode_handler 41 2.4 9 48 FF_Community __construct 12 0.0 7 15625 FF_Meta register_stuff 18 0.0 5 16 FF_Meta aux_get_all_locations 23 8.7 5 6 FF_Community make_from_city 15 0.0 4 20 [...]
  • 13. Example Plugin: Freifunkmeta ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 14. Unit Testing ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 15. Simple PHPUnit Test Case class LowLevelTests extends PHPUnit_Framework_TestCase { function setUp() { $this->FFM = new FF_Meta(); } function test_output_ff_state() { $data = array("state" => array("nodes" => 429)); $ret = $this->FFM->output_ff_state($data); $this->assertRegExp('/429/', $ret); } }
  • 16. Unit Testing (contd.) ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 17. Integration Testing ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 18. Unit Testing with Mock Object ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 19. Example: Test with Dependency Injection class MockDataService { function get($url) { return $some_fixed_data; } } class WpIntegrationTests extends WP_UnitTestCase { function setUp() { parent::setUp(); // get plugin instance and replace ext. data service: $this->plugin = $GLOBALS['wp-plugin-ffmeta']; $this->plugin->reset_external_data_service( new MockDataService() ); } // ...
  • 20. Example: Test with Dependency Injection // ... function test_post_ff_services() { $post_attribs = array( 'post_title' => 'Test', 'post_content' => '[ff_services]' ); $post = $this->factory->post->create_and_get( $post_attribs ); // w/o filter: $this->assertEquals($post_content, $post->post_content); // with filter: $output = apply_filters( 'the_content', $post->post_content ); $this->assertRegExp('/radio.ffhh/', $output); } }
  • 22. Behaviour Testing ..WP Blog. FF_Meta . WP Core . Other Plugins . FF_Community . FF_Dir . Output Formatter . HTTP Get Service
  • 23. WordPress Shortcode Plugin Test .. Feature: Use Shortcodes In order to use my Plugin As a website author I need to write posts with shortcodes Background: Given I am logged in as "admin" with "vagrant" Scenario: Without the plugin Given the plugin "freifunkmeta" is "inactive" When I write a post with title "test" and content "[ff_contact]" Then I should see "ff_contact" Scenario: With the plugin Given the plugin "freifunkmeta" is "active" When I write a post with title "test" and content "[ff_contact]" Then I should see "Twitter" in the ".ff_contact" element And I should not see "ff_contact"
  • 25. Implementation / Translation A look behind the curtain: • framework is clever but not magical • some translation needed • statements have to become executable code Mechanism: • plain sentence → method name • quoted words → arguments • matching with annotated regular expressions • methods yield success, exception, or pending exception
  • 26. Example: Behat Context (PHP) /** * from MinkContext * Checks, that page contains specified text. * * @Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)"$/ */ public function assertPageContainsText($text) { $this->assertSession()->pageTextContains( $this->fixStepArgument($text)); }
  • 27. The Big Picture ..Features. Step Definitions . WebDriver . Browser
  • 28. The Big Picture ..Features. Behat (PHP) . cucumber.js . Cucumber (Ruby) . PhantomJS . Goutte . Selenium . Firefox . Chrome
  • 29. Unit & Behaviour Testing Unit Tests • unit testing • programmers • programming language • bottom-up • assertXYZ • tests derived from user stories ⇒ development tool Behaviour Tests • acceptance test scenarios • non-developers • language of business domain • top-down / outside-in • X should do Y • execute user stories ⇒ design & communication tool
  • 31. Scripting Basis for all automation. Lots of useful builtins and packages: • wp core download/install/config/… • wp export/import • wp plugin get/install/update/… • wp scaffold _s/plugin/plugin-tests • wp server
  • 32. wp scaffold Generate skeleton code for a new plugin & unit tests: $ cd wordpress/wp-content/plugins $ wp scaffold plugin-tests awesome $ find awesome awesome/ awesome/awesome.php awesome/bin awesome/bin/install-wp-tests.sh awesome/tests awesome/tests/bootstrap.php awesome/tests/test-sample.php awesome/.travis.yml awesome/phpunit.xml
  • 33. wp scaffold (contd.) Create WP instance and run unit tests: $ cd awesome $ bash ./bin/install-wp-tests.sh wp_tests root vagrant latest ... $ phpunit PHPUnit 4.0.17 by Sebastian Bergmann. [...] Configuration read from [...]/plugins/awesome/phpunit.xml . Time: 5.52 seconds, Memory: 23.50Mb OK (1 test, 1 assertion)
  • 34. Version Control • use version control! • many possible workflows, e. g. branches for dev and release • use pre-commit hooks, e. g. with php -l syntax check
  • 35. Travis-CI Continuous Integration service for GitHub 1. gets notified on push 2. builds project 3. runs phpunit 4. summarizes results, alert on failure
  • 36. Example .travis.yml language: php php: - 5.4 - 5.5 - hhvm env: - WP_VERSION=3.8.3 - WP_VERSION=latest before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION script: phpunit
  • 38. Automated Testing Target: no manual effort. Continuous Integration: • frequent code check-ins • verified by automated builds and tests • quickly find bugs and regressions Continuous Deployment: • (semi-)automated deployment • plan for rollback
  • 39. Costs and Benefits of Testing • Testing (like Documentation) has a cost • usually: productivity improvement > cost • but find the right balance
  • 40. Conclusion I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence. – Kent Beck Links • http://phpqatools.org/: PHP Quality Assurance Toolchain • http://wpgear.org/: compendium of useful WP developer tools • http://wptest.io/: test data for WP plugins and themes • Ptah Dunbar: Automated Testing in WordPress, Really?! • tuts+ articles by Tom McFarlin • Conversation “Is TDD Dead?”