ACM CHT Best Inspection Practices Kinben Innovation MIC Slideshare.pdf
Automatic functional testing easier than you thought Bartosz Cisek
1. Functional testing easier than you thought
Bartosz Cisek
Edu-Space.pl
16.04.2014
Bartosz Cisek Functional testing easier than you thought 1 / 20
2. 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
3. Requirements
• php 5.4
• separate domain
• Internet access (only for installation)
Bartosz Cisek Functional testing easier than you thought 3 / 20
4. 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
5. Setup second platform
• First one runs test
• Second one is being tested
Bartosz Cisek Functional testing easier than you thought 5 / 20
6. Update configuration
• $CFG→behat prefix
• $CFG→behat dataroot
• $CFG→behat wwwroot
Bartosz Cisek Functional testing easier than you thought 6 / 20
7. 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.php
vendor/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
8. 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
9. 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
10. Feature and Scenario
• Feature – Human-readable list of scenarios that describes
a feature.
• Scenario – Human-readable list of steps to describe
an expected behavior
Bartosz Cisek Functional testing easier than you thought 10 / 20
11. 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
12. 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
13. 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
14. 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
15. 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
16. Filtering
• You can filter features to test with –tags or –name options
Bartosz Cisek Functional testing easier than you thought 16 / 20
17. Continuous Integration Manager
• Jenkins
• Computers are good at
repeating procedures
• Automate mundane tasks
Bartosz Cisek Functional testing easier than you thought 17 / 20
19. Flexibility
• Build script (ant, phing)
• Repository (git, hg, svn)
• Head less window manager – Xvfb
Bartosz Cisek Functional testing easier than you thought 19 / 20
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