Effizientere WordPress-Plugin-Entwicklung mit Softwaretests. Martin Schütte

Similar documents
Build & Launch Tools (BLT) Automating best practices for enterprise sites

Configuration Management

Technical Architecture & Analysis

" Qué me estás container?" Docker for dummies

A Sweet Test Suite. DrupalCon NA A Sweet Test Suite

Travis Cardwell Technical Meeting

Automated Testing in Drupal 8

TangeloHub Documentation

Continuous integration & continuous delivery. COSC345 Software Engineering

More Dev / Less Ops. Sean Dietrich DrupalCorn '18

Testing your puppet code

@EvanMHerman Introduction to Workflow Automation

Selenium Testing Course Content

WHO'S TALKING? Edvinas Aleksejonokas Member of OXID core team Joined two years ago

Managing a WordPress 2.6 installation with Subversion. Sam Bauers - Automattic

Having Fun with Social Coding. Sean Handley. February 25, 2010

Behat Drupal Integration Documentation

TM DevOps Use Case. 2017TechMinfy All Rights Reserved

Behat Kickstart. For Drupal 8 Developers. Stanford Drupal Camp 2016 Stanford, CA -- April 1-2, Peter Sawczynec Customer Success Engineer

Application Deployment

Index. Elad Elrom 2016 E. Elrom, Pro MEAN Stack Development, DOI /

projecto Documentation

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

Setting up VPS on Ovh public cloud and installing lamp server on Ubuntu instance

Chrome if I want to. What that should do, is have my specifications run against four different instances of Chrome, in parallel.

P a g e 0. CIDRZ Website Manual.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Drupal

Documentation. Visit the Documentation Online at:

platform Development Process Optimization For Drupal centric projects

Scaling with Continuous Deployment

Test all the things! Get productive with automated testing in Drupal 8. Sam Becker

BEHAVIOR DRIVEN DEVELOPMENT BDD GUIDE TO AGILE PRACTICES. Director, Strategic Solutions

Behat BDD, FUNCTIONAL TESTS & SELENIUM (IN DRUPAL!)

Azure DevOps. Randy Pagels Intelligent Cloud Technical Specialist Great Lakes Region

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

DEPLOYMENT MADE EASY!

Test Driven Development and Refactoring. CSC 440/540: Software Engineering Slide #1

FPLLL. Contributing. Martin R. Albrecht 2017/07/06

MANUAL+ SELENIUM CURRICULUM

Peter Sawczynec Engineer

Open Source Test Automation: Riding the Second Wave

Die drei Dimensionen des Testens. Sebastian Bergmann 4. Juli 2015

We want to install putty, an ssh client on the laptops. In the web browser goto:

Somerville College WordPress user manual. 7th October 2015

Simplified CICD with Jenkins and Git on the ZeroStack Platform

Emerging trends in test automation

Finding Vulnerabilities in Web Applications

Drupal Command Line Instructions Windows 7 List All Users >>>CLICK HERE<<<

WordPress is free and open source, meaning it's developed by the people who use it.

Software Continuous Integration & Delivery INCREASING SOFTWARE DEVELOPMENT AGILITY TO SPEED TIME TO MARKET

Final Paper/Best Practice/Tutorial Advantages OF BDD Testing

Automated Security Scanning in Payment Industry

Solar Plant Data Acquisition Maintenance

Software Testing

Docker for Development: Getting Started

CuteFlow-V4 Documentation

The InfluxDB-Grafana plugin for Fuel Documentation

Blogging using Wordpress

I've installed Wampserver 2.1d on Windows 8.1 as it is the nearest in php mysql the rewrite_module option on Apache and uncommented the LoadModule.

Publish Joomla! Article

Publish Joomla! Article

nacelle Documentation

WordPress Maintenance For Beginners

Software Development I

HTML presentation, positioning and designing responsive web applications.

Turbo boost your digital app test automation with Jenkins

Better Translation Technology. XTM Connect for WordPress

TDD: TEST DRIVEN DRUPAL

cwmon-mysql Release 0.5.0

Continuous Delivery for Python Developers PyCon 8, 2017

Selenium Training. Training Topics

Simulation Manager Configuration Guide

A TALE OF TWO APPS WHY DEVELOPMENT PRACTICES MATTER

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

WP EBOOKS Creating A WordPress Network

About Us. Services CONSULTING OUTSOURCING TRAINING MENTORING STAFF AUGMENTATION 9/9/2016

How to set up a continuous integration process in the cloud

Reviewer Plugin. Ultimate Reviews & User Ratings. Version Author: Michele Ivani Reviewer Plugin v. 3.6.

Make your IBM i Sizzle

CMS and e-commerce Solutions. version 1.0. Please, visit us at: or contact directly by

CodeCeption. introduction and use in Yii. Yii London Meetup - 15 April 2014 by Matteo Peach Pescarin

JUnit 3.8.1, 64. keep it simple stupid (KISS), 48

if (WP_DEBUG) E_ALL 'on'; }

Continuous Integration & Code Quality MINDS-ON NUNO 11 APRIL 2017

Welcome to you user manual for your website

Exercises. Cacti Installation and Configuration

Exercises. Cacti Installation and Configuration

Continuous Integration (CI) with Jenkins

Blog site (cont.) theme, 202 view creations, 205 Browser tools, 196 Buytaert, Dries, 185

WordPress SEO. Basic SEO Practices Using WordPress. Leo Wadsworth LeoWadsworth.com

Release Ralph Offinger

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. WordPress

Composer and Drupal. CIDUG Meeting December 13, 2018 John Rearick

Index. Chaminda Chandrasekara 2017 C. Chandrasekara, Beginning Build and Release Management with TFS 2017 and VSTS, DOI /

Relax-and-Recover (ReaR) Automated Testing

Index 1. Description 2. Examples 3. Installation 4. How to begin using

Vijaya Chandran

withenv Documentation

Creating pipelines that build, test and deploy containerized artifacts Slides: Tom Adams

Continuous Delivery for Cloud Native Applications

Transcription:

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 Acceptance Tests Integration Tests Unit Tests specific

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. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

Unit Testing WP Blog. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

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. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

Integration Testing WP Blog. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

Unit Testing with Mock Object WP Blog. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

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. WP Core FF_Meta Other Plugins FF_Dir FF_Community HTTP Get Service Output Formatter

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. cucumber.js Behat (PHP) Cucumber (Ruby) Goutte PhantomJS Selenium Chrome Firefox

Unit & Behaviour Testing Unit Tests Behaviour Tests unit testing acceptance test scenarios programmers non-developers programming language language of business domain bottom-up top-down / outside-in assertxyz X should do Y tests derived from user stories execute user stories development tool 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