Automatic functional testing easier than you thought Bartosz Cisek

Preview:

DESCRIPTION

Automatic functional testing easier than you thought Bartosz Cisek Presented at Edinburgh Moodlemoot 2014 www.moodlemoot.ie

Citation preview

Functional testing easier than you thought

Bartosz Cisek

Edu-Space.pl

16.04.2014

Bartosz Cisek Functional testing easier than you thought 1 / 20

Do not reinvent the wheel

Moodle already has:

• integrated testing framework

• well defined building blocks

• prepared scripts

• detailed documentation

Bartosz Cisek Functional testing easier than you thought 2 / 20

Requirements

• php 5.4

• separate domain

• Internet access (only for installation)

Bartosz Cisek Functional testing easier than you thought 3 / 20

Installation

• Download composer and let it do the rest.

• Download Selenium, Java and chrome driver.

Bartosz Cisek Functional testing easier than you thought 4 / 20

Setup second platform

• First one runs test

• Second one is being tested

Bartosz Cisek Functional testing easier than you thought 5 / 20

Update configuration

• $CFG→behat prefix

• $CFG→behat dataroot

• $CFG→behat wwwroot

Bartosz Cisek Functional testing easier than you thought 6 / 20

Test run

• Start Selenium

command line

java -jar selenium-server-standalone-2.NN.N.jar

• Start behat

command line

php admin/tool/behat/cli/init.phpvendor/bin/behat –config /behat/dataroot/behat/behat.yml

• As an example run tests of default Moodle installation

Bartosz Cisek Functional testing easier than you thought 7 / 20

Writing test cases

• start favorite editor

• yaml format

• create a file with .feature extension in tests/behat directory

Bartosz Cisek Functional testing easier than you thought 8 / 20

File structure

@plugintype @plugintype_plugin

Feature: feature name description

Scenario: Short description of scenario

step 1

step 2

Scenario: Another scenario to test this feature

step 1

step 2

Bartosz Cisek Functional testing easier than you thought 9 / 20

Feature and Scenario

• Feature – Human-readable list of scenarios that describesa feature.

• Scenario – Human-readable list of steps to describean expected behavior

Bartosz Cisek Functional testing easier than you thought 10 / 20

Scenario steps

• Steps – Human-readable sentences that describes an action.

• Steps definitions – php classes written in mink dialect

Bartosz Cisek Functional testing easier than you thought 11 / 20

Types of steps 1

• “Given” – describing the initial context

example

Given I log in as ”admin”

Bartosz Cisek Functional testing easier than you thought 12 / 20

Types of steps 2

• “When“ – action that leads to a change

example

When I click on a link

Bartosz Cisek Functional testing easier than you thought 13 / 20

Types of steps 3

• “Then” – check the results

example

Then I should see ”Moodle 101: Course Name”

Bartosz Cisek Functional testing easier than you thought 14 / 20

Fixtures

• Prepare predefined environment

• Testing enrollment requires users and courses

Given the following "courses" exist:

| fullname | shortname | category | format |

| Course 1 | COURSE1 | CAT1 | topics |

| Course 2 | COURSE2 | CAT2 | |

Bartosz Cisek Functional testing easier than you thought 15 / 20

Filtering

• You can filter features to test with –tags or –name options

Bartosz Cisek Functional testing easier than you thought 16 / 20

Continuous Integration Manager

• Jenkins

• Computers are good atrepeating procedures

• Automate mundane tasks

Bartosz Cisek Functional testing easier than you thought 17 / 20

Automatic Workflow

Bartosz Cisek Functional testing easier than you thought 18 / 20

Flexibility

• Build script (ant, phing)

• Repository (git, hg, svn)

• Head less window manager – Xvfb

Bartosz Cisek Functional testing easier than you thought 19 / 20

Summary

• It is not rocket science!

• http://docs.moodle.org/dev/Acceptance_testing

Contact:

• b.cisek@edu-space.pl

• +48 604 874 555

Bartosz Cisek Functional testing easier than you thought 20 / 20

Recommended