SlideShare una empresa de Scribd logo
1 de 43
Dagfinn Reiersøl, ABC Startsiden 1
Reliable acceptance testing
Dagfinn Reiersøl, ABC Startsiden 2
Manual testing is immoral
• Not what humans are good at
• Time consuming = expensive
• High stress
• Error-prone
• Exception: exploratory testing
Dagfinn Reiersøl, ABC Startsiden 3
Types of automated testing
• Unit tests: clean code
• Acceptance tests: communicate with user / customer
• Other functional tests: ensure that everything works
Dagfinn Reiersøl, ABC Startsiden 4
High-level challenges of
acceptance testing
• Getting the Product Owner involved
• Test Doubles
• Not over-testing the user interface
Dagfinn Reiersøl, ABC Startsiden 5
Unit tests
• Keep code clean
• Avoid “hidden” bugs
• Aid design
• Test-driven development
Dagfinn Reiersøl, ABC Startsiden 6
Scrum Product Owner
• Represents customer(s) and other stakeholders
• Owns the product backlog
• Is not a developer
Dagfinn Reiersøl, ABC Startsiden 7
Acceptance tests
• For the Product Owner or possibly testers
• Goal: Make sure we implement the right features
• Ideally editable by a non-programmer
• Tests features, not modules
• Make sure you're done
Dagfinn Reiersøl, ABC Startsiden 8
Other functional tests
• Goal: Make sure the implementation works
• Could be testing the same thing as acceptance tests, but
• need not be business-readable
Dagfinn Reiersøl, ABC Startsiden 9
The Test Double pattern
Dagfinn Reiersøl, ABC Startsiden 10
Surrounded by “Test Doubles”
Dagfinn Reiersøl, ABC Startsiden 11
Web testing: advantages
• You can test exactly what the user sees
• There are tools to test JavaScript-heavy / Ajax apps
• There are tools to record and play back tests
• “It seemed like an good idea at the time”
Dagfinn Reiersøl, ABC Startsiden 12
Web testing: disadvantages
• Fragile: Small UI changes break tests
• Fragile: External services break tests
• Slow
• Harder to replace external services with fakes
Dagfinn Reiersøl, ABC Startsiden 13
Strategies for robustness
• Test Bus
• Test patterns
• Test refactoring
• Making tests unnecessary
Dagfinn Reiersøl, ABC Startsiden 14
Web testing: essentials
• Must be in a programming language (conditionals, variables)
• Language not necessarily PHP, since HTTP allows
communication between languages
• “Business-readable” programming language (FitNesse wiki,
Gherkin...)
Dagfinn Reiersøl, ABC Startsiden 15
Web testing tips
• Test the HTML output using regex, XPath, CSS selector
• Use element IDs or names to test links, forms and fields
• Log HTTP requests in the application
Dagfinn Reiersøl, ABC Startsiden 16
How to use the request log
Automated test fails but not manual run from browser
• Run the automated test, find the failing request in the log.
• Run the app manually, find the successful request in the log.
• Compare.
Dagfinn Reiersøl, ABC Startsiden 17
Using SimpleTest
<?php
require_once 'simpletest/autorun.php';
require_once 'simpletest/web_tester.php';
error_reporting (E_ALL);
class JoomlaSimpleTestTest extends WebTestCase {
function testJoomla() {
$this->get('http://localhost/joomla');
$this->assertResponse(200);
$this->assertTitle('Welcome to the Frontpage');
$this->assertText('Welcome to the Frontpage');
$this->click('Welcome to Joomla!');
$this->assertPattern('/Joomla! is a free.*content
publishing system/is');
}
}
Dagfinn Reiersøl, ABC Startsiden 18
Using PHPUnit with Selenium
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class JoomlaPhpUnitTest extends
PHPUnit_Extensions_SeleniumTestCase {
protected function setUp(){
$this->setBrowser('*firefox');
$this->setBrowserUrl('http://localhost/');
}
public function testJoomla() {
$this->open('http://localhost/joomla/');
$this->assertTitle('Welcome to the Frontpage');
$this->assertTextPresent('Welcome to the Frontpage');
$this ->clickAndWait(
'//ul[@class='latestnews']/li[4]/a');
$this ->assertTextPresent('Joomla! is a free open');
}
}
Dagfinn Reiersøl, ABC Startsiden 19
SimpleTest vs. PHPUnit /
Selenium
Simpletest:
– Faster
– Easier to use
PHPUnit with Selenium
– Heavier but more advanced
– Can test JavaScript-heavy / Ajax apps
– Can test cross-browser compatibility
Dagfinn Reiersøl, ABC Startsiden 20
Don't overdo Selenium
“He ate a lot of brazil nuts which is a big deal because they
contain selenium, which in high doses causes fatigue,
vomiting, skin irritation, discharge from the fingernail beds and
hair loss.”
- House, M.D.
Dagfinn Reiersøl, ABC Startsiden 21
Acceptance test frameworks
• FitNesse: has specific support for PHP
• Cucumber: has PHP-related documentation
• Robot Framework
• Concordion
Dagfinn Reiersøl, ABC Startsiden 22
Using FitNesse with SimpleTest
Dagfinn Reiersøl, ABC Startsiden 23
PhpSlim Fixture for FitNesse test
(simplistic!)
<?php
require_once 'simpletest/browser.php';
class SimpleTestFixture {
function __construct() {
$this->browser = new SimpleBrowser;
}
function goToPage($url) {
$this->content = $this->browser->get($url);
return !empty($this->content);
}
function pattern($pattern) {
return preg_match("/$pattern/is",$this->content) > 0;
}
}
Dagfinn Reiersøl, ABC Startsiden 24
Using Cucumber with Webrat
• joomla.feature (Cucumber Gherkin business-readable)
• webrat_steps (Ruby code testing via HTTP)
Feature: Joomla welcome
In order to understand what Joomla is
As a potential user
I want to be able to read an introduction to Joomla
Scenario: Welcome page
Given I am on the home page
When I follow "Welcome to Joomla!"
Then I should see "Joomla! is a"
Dagfinn Reiersøl, ABC Startsiden 25
Webrat steps for Cucumber
• Ruby code runs Webrat which runs the web app using HTTP
Given /^I am on (.+)$/ do |page_name|
  visit path_to(page_name)
end
When /^I follow "([^"]*)"$/ do |link|
  click_link (link)
end
 Then /^I should see "([^"]*)"$/ do |text|
  response_body.should contain(text)
end
Dagfinn Reiersøl, ABC Startsiden 26
Avoiding difficult tests
• It's hard to test behaviors that cut across the HTTP request
• Improve architecture so these behaviors can't fail
• Example: duplication between input control name and HTTP
variable name
Dagfinn Reiersøl, ABC Startsiden 27
Hard to test: name duplication
<input type="text" name="address1"
value="<?= $address1 ?>">
// Oops...
echo $_POST['address_1'];
Dagfinn Reiersøl, ABC Startsiden 28
Getting rid of name duplication
• Use a form handling package
• Or do it yourself. Simplistic version here:
<?php
define('ADDRESS1_NAME', 'address1');
$address1_value = $_POST[ADDRESS1_NAME];
<html>
...
<input name="<?= ADDRESS1_NAME ?>" value="<?=
$address1_value ?>">
Dagfinn Reiersøl, ABC Startsiden 29
Refactoring tests
• Refactor or be doomed to drown in duplicate code
• Especially true of web tests
• Most important: eliminate duplication
Dagfinn Reiersøl, ABC Startsiden 30
BDD-style test names
class JoomlaSimpleTestTest extends WebTestCase {
    function setUp() {
        $this­>get('http://localhost/joomla');
    }
    function testFrontPageIsValid() {
        $this­>assertResponse(200);
        $this­>assertTitle('Welcome to the Frontpage');
        $this­>assertText('Welcome to the Frontpage');
    }
    function testWelcomePageIsValid() {
        $this­>click('Welcome to Joomla!');
        $this­>assertPattern('/Joomla! is a free.*content 
publishing system/is');
    }
}
Dagfinn Reiersøl, ABC Startsiden 31
Using custom assertions instead
class JoomlaSimpleTestTest extends WebTestCase {
    function testJoomla() {
        $this­>get('http://localhost/joomla');
        $this­>assertValidHomePage();
        $this­>click('Welcome to Joomla!');
        $this­>assertValidWelcomePage();
    }
    function assertValidHomePage() {
        $msg = 'Error on home page';
        $this­>assertResponse(200,$msg);
        $this­>assertTitle('Welcome to the Frontpage',$msg);
        $this­>assertText('Welcome to the Fontpage',$msg);
    }
    function assertValidWelcomePage() {
        $this­>assertPattern(
           '/Joomla! is a free.*content publishing system/is',
           'Error on welcome page');
    }
Dagfinn Reiersøl, ABC Startsiden 32
ComposedRegex
http://martinfowler.com/bliki/ComposedRegex.html
• This regex tolerates markup (or anything else) between the
content items
• Yes, I know the email regex is simplistic
$email = '.*w+@w+.w+.*';
        $firstname = '.*w.*';
        $lastname = '.*w.*';
        $date = '.*20dd­dd­dd( |&nbsp;|T)dd:dd.*';
        $regex = 'Email address:'. $email .
                  'Name: ' . $firstname . $lastname .
                  'Date:' . $date;
Dagfinn Reiersøl, ABC Startsiden 33
Re-using setup
• Refactor gradually as needed:
– When test class gets big, split it and...
– ...extract setup method into a separate class
– When setup is common to many tests...
– ...extract setup class into a separate file
class JoomlaTestSetup {
    function setUp() {
        $this­>get('http://localhost/joomla');
    }
}
class JoomlaSimpleTestTest extends JoomlaTestSetup..
Dagfinn Reiersøl, ABC Startsiden 34
Useful types of classes in web
testing
• Scraper
• Domain Object
• Specification
Dagfinn Reiersøl, ABC Startsiden 35
Domain object test version
class UserTest extends WebTestCase {
    function setUp() {
        $this­>user = new TestUser(
            'Jane','Doe','jane@example.com');
    }
    function testCanRegisterUser...
        $this­>setFieldByName(
            'firstname',
           $this­>user­>firstname
        );
Dagfinn Reiersøl, ABC Startsiden 36
Given-when-then in PHP
class JoomlaSimpleTestTest extends WebTestCase {
    function setUp() {
        $this­>pages = array(
            'JoomlaHomePage' => 'http://localhost/joomla');
    }
    function testWelcomPageIsValid() {
        $this­>givenIAmOn('JoomlaHomePage');
        $this­>whenIFollow('Welcome to Joomla!');
        $this­>thenIShouldSee('Joomla! is a free');
    }
    function givenIAmOn($name) {
        $this­>get($this­>pages[$name]);
    }
    function whenIFollow($text) {
       $this­>clickLink($text); 
    }
    function thenIShouldSee($pattern) {
        $this­>assertPattern("/$pattern/is");
    }
Dagfinn Reiersøl, ABC Startsiden 37
Test bus
http://www.martinfowler.com/ieeeSoftware/testBus.pdf
Dagfinn Reiersøl, ABC Startsiden 38
Recommendations from Uncle
Bob
• Test the features through the test bus
• Test the user interface separately in isolation
• Run a few end-to-end tests to test the “plumbing”
Dagfinn Reiersøl, ABC Startsiden 39
Test bus
Where is the test bus? Some possbilities:
• Test the Model
• Test the Controller
• Test the server side of an Ajax or “thin server” application
• Test a public API
Dagfinn Reiersøl, ABC Startsiden 40
Test bus with presentation tests
Dagfinn Reiersøl, ABC Startsiden 41
Fake web service
• Easier to do when not
testing via HTTP
• Sensing/verification is
very hard to do
Dagfinn Reiersøl, ABC Startsiden 42
Self-initializing fake
http://martinfowler.com/bliki/SelfInitializingFake.html
Dagfinn Reiersøl, ABC Startsiden 43
Self-initializing fake
http://martinfowler.com/bliki/SelfInitializingFake.html

Más contenido relacionado

La actualidad más candente

BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /CapybaraShraddhaSF
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great JusticeDomenic Denicola
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slidesMasterCode.vn
 
CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011Graham Weldon
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewAl Sargent
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...seleniumconf
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency HeavenOpusVL
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13DanWooster1
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTPMykhailo Kolesnyk
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flaskjuzten
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
CakePHP - The Path to 2.0
CakePHP - The Path to 2.0CakePHP - The Path to 2.0
CakePHP - The Path to 2.0Graham Weldon
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
Web API Test Automation using Frisby & Node.js
Web API Test Automation using Frisby  & Node.jsWeb API Test Automation using Frisby  & Node.js
Web API Test Automation using Frisby & Node.jsChi Lang Le Vu Tran
 

La actualidad más candente (20)

BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides
 
CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011CakePHP 2.0 - PHP Matsuri 2011
CakePHP 2.0 - PHP Matsuri 2011
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program Overview
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency Heaven
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
CakePHP - The Path to 2.0
CakePHP - The Path to 2.0CakePHP - The Path to 2.0
CakePHP - The Path to 2.0
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Web API Test Automation using Frisby & Node.js
Web API Test Automation using Frisby  & Node.jsWeb API Test Automation using Frisby  & Node.js
Web API Test Automation using Frisby & Node.js
 

Destacado

Hannah Top 10
Hannah Top 10Hannah Top 10
Hannah Top 10ndavis1
 
10 things about_danielle
10 things about_danielle10 things about_danielle
10 things about_daniellendavis1
 
Refactoring tools for Perl code
Refactoring tools for Perl codeRefactoring tools for Perl code
Refactoring tools for Perl codeDagfinn Reiersøl
 
Top 10 things_mazlyn
Top 10 things_mazlynTop 10 things_mazlyn
Top 10 things_mazlynndavis1
 
Improvedncorre2
Improvedncorre2Improvedncorre2
Improvedncorre2ndavis1
 
The million dollar_project_kayla
The million dollar_project_kaylaThe million dollar_project_kayla
The million dollar_project_kaylandavis1
 
Top ten things_about_me juliana
Top ten things_about_me julianaTop ten things_about_me juliana
Top ten things_about_me julianandavis1
 
Blauwe Oceaan
Blauwe OceaanBlauwe Oceaan
Blauwe Oceaannienke36
 
Innovatiegroeimodel
InnovatiegroeimodelInnovatiegroeimodel
Innovatiegroeimodelnienke36
 
10 special things_about_karla
10 special things_about_karla10 special things_about_karla
10 special things_about_karlandavis1
 
Ten things about_me ahmad
Ten things about_me ahmadTen things about_me ahmad
Ten things about_me ahmadndavis1
 
Ford vinson
Ford vinsonFord vinson
Ford vinsonndavis1
 
Postennet In Perspectief
Postennet In PerspectiefPostennet In Perspectief
Postennet In PerspectiefBongers
 
10 things about me!!! madison
10 things about me!!! madison10 things about me!!! madison
10 things about me!!! madisonndavis1
 
Backbone.js versus AngularJS
Backbone.js versus AngularJSBackbone.js versus AngularJS
Backbone.js versus AngularJSDagfinn Reiersøl
 
Blauwe Oceaan
Blauwe OceaanBlauwe Oceaan
Blauwe Oceaannienke36
 
Tim mckay s_top_10-1
Tim mckay s_top_10-1Tim mckay s_top_10-1
Tim mckay s_top_10-1ndavis1
 
Speaking the same language: Harmonizing how we measure stockouts and availabi...
Speaking the same language: Harmonizing how we measure stockouts and availabi...Speaking the same language: Harmonizing how we measure stockouts and availabi...
Speaking the same language: Harmonizing how we measure stockouts and availabi...JSI
 
Speaking skills.finall
Speaking skills.finallSpeaking skills.finall
Speaking skills.finallArifa Abid
 

Destacado (20)

Bai giang-spm-13feb14
Bai giang-spm-13feb14Bai giang-spm-13feb14
Bai giang-spm-13feb14
 
Hannah Top 10
Hannah Top 10Hannah Top 10
Hannah Top 10
 
10 things about_danielle
10 things about_danielle10 things about_danielle
10 things about_danielle
 
Refactoring tools for Perl code
Refactoring tools for Perl codeRefactoring tools for Perl code
Refactoring tools for Perl code
 
Top 10 things_mazlyn
Top 10 things_mazlynTop 10 things_mazlyn
Top 10 things_mazlyn
 
Improvedncorre2
Improvedncorre2Improvedncorre2
Improvedncorre2
 
The million dollar_project_kayla
The million dollar_project_kaylaThe million dollar_project_kayla
The million dollar_project_kayla
 
Top ten things_about_me juliana
Top ten things_about_me julianaTop ten things_about_me juliana
Top ten things_about_me juliana
 
Blauwe Oceaan
Blauwe OceaanBlauwe Oceaan
Blauwe Oceaan
 
Innovatiegroeimodel
InnovatiegroeimodelInnovatiegroeimodel
Innovatiegroeimodel
 
10 special things_about_karla
10 special things_about_karla10 special things_about_karla
10 special things_about_karla
 
Ten things about_me ahmad
Ten things about_me ahmadTen things about_me ahmad
Ten things about_me ahmad
 
Ford vinson
Ford vinsonFord vinson
Ford vinson
 
Postennet In Perspectief
Postennet In PerspectiefPostennet In Perspectief
Postennet In Perspectief
 
10 things about me!!! madison
10 things about me!!! madison10 things about me!!! madison
10 things about me!!! madison
 
Backbone.js versus AngularJS
Backbone.js versus AngularJSBackbone.js versus AngularJS
Backbone.js versus AngularJS
 
Blauwe Oceaan
Blauwe OceaanBlauwe Oceaan
Blauwe Oceaan
 
Tim mckay s_top_10-1
Tim mckay s_top_10-1Tim mckay s_top_10-1
Tim mckay s_top_10-1
 
Speaking the same language: Harmonizing how we measure stockouts and availabi...
Speaking the same language: Harmonizing how we measure stockouts and availabi...Speaking the same language: Harmonizing how we measure stockouts and availabi...
Speaking the same language: Harmonizing how we measure stockouts and availabi...
 
Speaking skills.finall
Speaking skills.finallSpeaking skills.finall
Speaking skills.finall
 

Similar a Reliable acceptance testing

Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development IntroductionNguyen Hai
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Niels Frydenholm
 
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A CookbookJavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A CookbookJorge Hidalgo
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Dinis Cruz
 
Selenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applicationsSelenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applicationsTSundberg
 
Use Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationUse Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationClever Moe
 
Approval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience ReportApproval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience Reporthouseofyin
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing SoftwareSteven Smith
 
Automating testing with open source tools (1)
Automating testing with open source tools (1)Automating testing with open source tools (1)
Automating testing with open source tools (1)Rohit Biradar
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentZendCon
 
Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014Clever Moe
 
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth ConsultingUnit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth ConsultingDave White
 
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source ToolsTYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source ToolsMichael Lihs
 

Similar a Reliable acceptance testing (20)

Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...Getting your mobile test automation process in place - using Cucumber and Cal...
Getting your mobile test automation process in place - using Cucumber and Cal...
 
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A CookbookJavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Selenium
SeleniumSelenium
Selenium
 
Selenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applicationsSelenium WebDriver - Test automation for web applications
Selenium WebDriver - Test automation for web applications
 
Use Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationUse Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test Automation
 
Approval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience ReportApproval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience Report
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
DevOps and AWS
DevOps and AWSDevOps and AWS
DevOps and AWS
 
Automating testing with open source tools (1)
Automating testing with open source tools (1)Automating testing with open source tools (1)
Automating testing with open source tools (1)
 
Selenium
SeleniumSelenium
Selenium
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014
 
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth ConsultingUnit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
 
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source ToolsTYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
TYPO3 Camp Stuttgart 2015 - Continuous Delivery with Open Source Tools
 

Último

Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 

Último (20)

Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

Reliable acceptance testing

  • 1. Dagfinn Reiersøl, ABC Startsiden 1 Reliable acceptance testing
  • 2. Dagfinn Reiersøl, ABC Startsiden 2 Manual testing is immoral • Not what humans are good at • Time consuming = expensive • High stress • Error-prone • Exception: exploratory testing
  • 3. Dagfinn Reiersøl, ABC Startsiden 3 Types of automated testing • Unit tests: clean code • Acceptance tests: communicate with user / customer • Other functional tests: ensure that everything works
  • 4. Dagfinn Reiersøl, ABC Startsiden 4 High-level challenges of acceptance testing • Getting the Product Owner involved • Test Doubles • Not over-testing the user interface
  • 5. Dagfinn Reiersøl, ABC Startsiden 5 Unit tests • Keep code clean • Avoid “hidden” bugs • Aid design • Test-driven development
  • 6. Dagfinn Reiersøl, ABC Startsiden 6 Scrum Product Owner • Represents customer(s) and other stakeholders • Owns the product backlog • Is not a developer
  • 7. Dagfinn Reiersøl, ABC Startsiden 7 Acceptance tests • For the Product Owner or possibly testers • Goal: Make sure we implement the right features • Ideally editable by a non-programmer • Tests features, not modules • Make sure you're done
  • 8. Dagfinn Reiersøl, ABC Startsiden 8 Other functional tests • Goal: Make sure the implementation works • Could be testing the same thing as acceptance tests, but • need not be business-readable
  • 9. Dagfinn Reiersøl, ABC Startsiden 9 The Test Double pattern
  • 10. Dagfinn Reiersøl, ABC Startsiden 10 Surrounded by “Test Doubles”
  • 11. Dagfinn Reiersøl, ABC Startsiden 11 Web testing: advantages • You can test exactly what the user sees • There are tools to test JavaScript-heavy / Ajax apps • There are tools to record and play back tests • “It seemed like an good idea at the time”
  • 12. Dagfinn Reiersøl, ABC Startsiden 12 Web testing: disadvantages • Fragile: Small UI changes break tests • Fragile: External services break tests • Slow • Harder to replace external services with fakes
  • 13. Dagfinn Reiersøl, ABC Startsiden 13 Strategies for robustness • Test Bus • Test patterns • Test refactoring • Making tests unnecessary
  • 14. Dagfinn Reiersøl, ABC Startsiden 14 Web testing: essentials • Must be in a programming language (conditionals, variables) • Language not necessarily PHP, since HTTP allows communication between languages • “Business-readable” programming language (FitNesse wiki, Gherkin...)
  • 15. Dagfinn Reiersøl, ABC Startsiden 15 Web testing tips • Test the HTML output using regex, XPath, CSS selector • Use element IDs or names to test links, forms and fields • Log HTTP requests in the application
  • 16. Dagfinn Reiersøl, ABC Startsiden 16 How to use the request log Automated test fails but not manual run from browser • Run the automated test, find the failing request in the log. • Run the app manually, find the successful request in the log. • Compare.
  • 17. Dagfinn Reiersøl, ABC Startsiden 17 Using SimpleTest <?php require_once 'simpletest/autorun.php'; require_once 'simpletest/web_tester.php'; error_reporting (E_ALL); class JoomlaSimpleTestTest extends WebTestCase { function testJoomla() { $this->get('http://localhost/joomla'); $this->assertResponse(200); $this->assertTitle('Welcome to the Frontpage'); $this->assertText('Welcome to the Frontpage'); $this->click('Welcome to Joomla!'); $this->assertPattern('/Joomla! is a free.*content publishing system/is'); } }
  • 18. Dagfinn Reiersøl, ABC Startsiden 18 Using PHPUnit with Selenium <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class JoomlaPhpUnitTest extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp(){ $this->setBrowser('*firefox'); $this->setBrowserUrl('http://localhost/'); } public function testJoomla() { $this->open('http://localhost/joomla/'); $this->assertTitle('Welcome to the Frontpage'); $this->assertTextPresent('Welcome to the Frontpage'); $this ->clickAndWait( '//ul[@class='latestnews']/li[4]/a'); $this ->assertTextPresent('Joomla! is a free open'); } }
  • 19. Dagfinn Reiersøl, ABC Startsiden 19 SimpleTest vs. PHPUnit / Selenium Simpletest: – Faster – Easier to use PHPUnit with Selenium – Heavier but more advanced – Can test JavaScript-heavy / Ajax apps – Can test cross-browser compatibility
  • 20. Dagfinn Reiersøl, ABC Startsiden 20 Don't overdo Selenium “He ate a lot of brazil nuts which is a big deal because they contain selenium, which in high doses causes fatigue, vomiting, skin irritation, discharge from the fingernail beds and hair loss.” - House, M.D.
  • 21. Dagfinn Reiersøl, ABC Startsiden 21 Acceptance test frameworks • FitNesse: has specific support for PHP • Cucumber: has PHP-related documentation • Robot Framework • Concordion
  • 22. Dagfinn Reiersøl, ABC Startsiden 22 Using FitNesse with SimpleTest
  • 23. Dagfinn Reiersøl, ABC Startsiden 23 PhpSlim Fixture for FitNesse test (simplistic!) <?php require_once 'simpletest/browser.php'; class SimpleTestFixture { function __construct() { $this->browser = new SimpleBrowser; } function goToPage($url) { $this->content = $this->browser->get($url); return !empty($this->content); } function pattern($pattern) { return preg_match("/$pattern/is",$this->content) > 0; } }
  • 24. Dagfinn Reiersøl, ABC Startsiden 24 Using Cucumber with Webrat • joomla.feature (Cucumber Gherkin business-readable) • webrat_steps (Ruby code testing via HTTP) Feature: Joomla welcome In order to understand what Joomla is As a potential user I want to be able to read an introduction to Joomla Scenario: Welcome page Given I am on the home page When I follow "Welcome to Joomla!" Then I should see "Joomla! is a"
  • 25. Dagfinn Reiersøl, ABC Startsiden 25 Webrat steps for Cucumber • Ruby code runs Webrat which runs the web app using HTTP Given /^I am on (.+)$/ do |page_name|   visit path_to(page_name) end When /^I follow "([^"]*)"$/ do |link|   click_link (link) end  Then /^I should see "([^"]*)"$/ do |text|   response_body.should contain(text) end
  • 26. Dagfinn Reiersøl, ABC Startsiden 26 Avoiding difficult tests • It's hard to test behaviors that cut across the HTTP request • Improve architecture so these behaviors can't fail • Example: duplication between input control name and HTTP variable name
  • 27. Dagfinn Reiersøl, ABC Startsiden 27 Hard to test: name duplication <input type="text" name="address1" value="<?= $address1 ?>"> // Oops... echo $_POST['address_1'];
  • 28. Dagfinn Reiersøl, ABC Startsiden 28 Getting rid of name duplication • Use a form handling package • Or do it yourself. Simplistic version here: <?php define('ADDRESS1_NAME', 'address1'); $address1_value = $_POST[ADDRESS1_NAME]; <html> ... <input name="<?= ADDRESS1_NAME ?>" value="<?= $address1_value ?>">
  • 29. Dagfinn Reiersøl, ABC Startsiden 29 Refactoring tests • Refactor or be doomed to drown in duplicate code • Especially true of web tests • Most important: eliminate duplication
  • 30. Dagfinn Reiersøl, ABC Startsiden 30 BDD-style test names class JoomlaSimpleTestTest extends WebTestCase {     function setUp() {         $this­>get('http://localhost/joomla');     }     function testFrontPageIsValid() {         $this­>assertResponse(200);         $this­>assertTitle('Welcome to the Frontpage');         $this­>assertText('Welcome to the Frontpage');     }     function testWelcomePageIsValid() {         $this­>click('Welcome to Joomla!');         $this­>assertPattern('/Joomla! is a free.*content  publishing system/is');     } }
  • 31. Dagfinn Reiersøl, ABC Startsiden 31 Using custom assertions instead class JoomlaSimpleTestTest extends WebTestCase {     function testJoomla() {         $this­>get('http://localhost/joomla');         $this­>assertValidHomePage();         $this­>click('Welcome to Joomla!');         $this­>assertValidWelcomePage();     }     function assertValidHomePage() {         $msg = 'Error on home page';         $this­>assertResponse(200,$msg);         $this­>assertTitle('Welcome to the Frontpage',$msg);         $this­>assertText('Welcome to the Fontpage',$msg);     }     function assertValidWelcomePage() {         $this­>assertPattern(            '/Joomla! is a free.*content publishing system/is',            'Error on welcome page');     }
  • 32. Dagfinn Reiersøl, ABC Startsiden 32 ComposedRegex http://martinfowler.com/bliki/ComposedRegex.html • This regex tolerates markup (or anything else) between the content items • Yes, I know the email regex is simplistic $email = '.*w+@w+.w+.*';         $firstname = '.*w.*';         $lastname = '.*w.*';         $date = '.*20dd­dd­dd( |&nbsp;|T)dd:dd.*';         $regex = 'Email address:'. $email .                   'Name: ' . $firstname . $lastname .                   'Date:' . $date;
  • 33. Dagfinn Reiersøl, ABC Startsiden 33 Re-using setup • Refactor gradually as needed: – When test class gets big, split it and... – ...extract setup method into a separate class – When setup is common to many tests... – ...extract setup class into a separate file class JoomlaTestSetup {     function setUp() {         $this­>get('http://localhost/joomla');     } } class JoomlaSimpleTestTest extends JoomlaTestSetup..
  • 34. Dagfinn Reiersøl, ABC Startsiden 34 Useful types of classes in web testing • Scraper • Domain Object • Specification
  • 35. Dagfinn Reiersøl, ABC Startsiden 35 Domain object test version class UserTest extends WebTestCase {     function setUp() {         $this­>user = new TestUser(             'Jane','Doe','jane@example.com');     }     function testCanRegisterUser...         $this­>setFieldByName(             'firstname',            $this­>user­>firstname         );
  • 36. Dagfinn Reiersøl, ABC Startsiden 36 Given-when-then in PHP class JoomlaSimpleTestTest extends WebTestCase {     function setUp() {         $this­>pages = array(             'JoomlaHomePage' => 'http://localhost/joomla');     }     function testWelcomPageIsValid() {         $this­>givenIAmOn('JoomlaHomePage');         $this­>whenIFollow('Welcome to Joomla!');         $this­>thenIShouldSee('Joomla! is a free');     }     function givenIAmOn($name) {         $this­>get($this­>pages[$name]);     }     function whenIFollow($text) {        $this­>clickLink($text);      }     function thenIShouldSee($pattern) {         $this­>assertPattern("/$pattern/is");     }
  • 37. Dagfinn Reiersøl, ABC Startsiden 37 Test bus http://www.martinfowler.com/ieeeSoftware/testBus.pdf
  • 38. Dagfinn Reiersøl, ABC Startsiden 38 Recommendations from Uncle Bob • Test the features through the test bus • Test the user interface separately in isolation • Run a few end-to-end tests to test the “plumbing”
  • 39. Dagfinn Reiersøl, ABC Startsiden 39 Test bus Where is the test bus? Some possbilities: • Test the Model • Test the Controller • Test the server side of an Ajax or “thin server” application • Test a public API
  • 40. Dagfinn Reiersøl, ABC Startsiden 40 Test bus with presentation tests
  • 41. Dagfinn Reiersøl, ABC Startsiden 41 Fake web service • Easier to do when not testing via HTTP • Sensing/verification is very hard to do
  • 42. Dagfinn Reiersøl, ABC Startsiden 42 Self-initializing fake http://martinfowler.com/bliki/SelfInitializingFake.html
  • 43. Dagfinn Reiersøl, ABC Startsiden 43 Self-initializing fake http://martinfowler.com/bliki/SelfInitializingFake.html