20

Click here to load reader

Automatic functional testing easier than you thought Bartosz Cisek

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Automatic functional testing easier than you thought Bartosz Cisek

Functional testing easier than you thought

Bartosz Cisek

Edu-Space.pl

16.04.2014

Bartosz Cisek Functional testing easier than you thought 1 / 20

Page 2: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 3: Automatic functional testing easier than you thought Bartosz Cisek

Requirements

• php 5.4

• separate domain

• Internet access (only for installation)

Bartosz Cisek Functional testing easier than you thought 3 / 20

Page 4: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 5: Automatic functional testing easier than you thought Bartosz Cisek

Setup second platform

• First one runs test

• Second one is being tested

Bartosz Cisek Functional testing easier than you thought 5 / 20

Page 6: Automatic functional testing easier than you thought Bartosz Cisek

Update configuration

• $CFG→behat prefix

• $CFG→behat dataroot

• $CFG→behat wwwroot

Bartosz Cisek Functional testing easier than you thought 6 / 20

Page 7: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 8: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 9: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 10: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 11: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 12: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 13: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 14: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 15: Automatic functional testing easier than you thought Bartosz Cisek

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

Page 16: Automatic functional testing easier than you thought Bartosz Cisek

Filtering

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

Bartosz Cisek Functional testing easier than you thought 16 / 20

Page 17: Automatic functional testing easier than you thought Bartosz Cisek

Continuous Integration Manager

• Jenkins

• Computers are good atrepeating procedures

• Automate mundane tasks

Bartosz Cisek Functional testing easier than you thought 17 / 20

Page 18: Automatic functional testing easier than you thought Bartosz Cisek

Automatic Workflow

Bartosz Cisek Functional testing easier than you thought 18 / 20

Page 19: Automatic functional testing easier than you thought Bartosz Cisek

Flexibility

• Build script (ant, phing)

• Repository (git, hg, svn)

• Head less window manager – Xvfb

Bartosz Cisek Functional testing easier than you thought 19 / 20

Page 20: Automatic functional testing easier than you thought Bartosz Cisek

Summary

• It is not rocket science!

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

Contact:

[email protected]

• +48 604 874 555

Bartosz Cisek Functional testing easier than you thought 20 / 20