Testing Area/Behat Testing/Characteristics of a good test
From Mahara Wiki
< Testing Area | Behat Testing
How to write a good test
Template
Copy and paste into your text editor and remember to save in the right directory and as a .feature file
Single scenario on a page
@javascript @core Feature: In order to As an So I can Scenario: Given And When And Then
Multiple scenarios on one page.
@javascript @core Feature: In order to As an So I can Background: Given And And And @core_ Scenario: Given And When And Then @core_ Scenario: Given And When And Then
Tags
The tags are how we run the tests, to run a group of tests on Jenkins at once we identify the ones to run by the tag.
- Always attach an @javascript tag to the top of the page. This will run all the scenarios on the page, don't tag each scenario with @javasript. One at the top is enough.
- If it's testing a core feature tag it @core, this will be all tests except 3rd party plugins.
- Tags at the top of the page, run all the scenarios on the page.
- Tags on the scenarios just run those scenarios.
- If there are multiple scenarios on the page and they are testing are testing multiple parts of a feature, tag the top of the scenario appropriately.
Feature
Behat docs on Features:[1]
- Good features clearly explain what you are trying to do. If you are using a bug from Launchpad to write the test, use the title of the bug in the title of the feature.
Feature: Creating a group In order to create a group As a student So I can become a part of the group and share my work
- The first line of the feature is the title of what you are testing
- In order to do something specific
- As an, who you are logging in as (remember if you are logggin in as a student you first need to have the student account created, use the background for this)
- So I can, tell us what the end game is here. So you can do what?
Background
Behat docs on backgrounds:[2]
- Backgrounds come after the feature and before the first scenario and cannot be placed on any other part of the test.
- Backgrounds are good for efficiency and save you from having to write the same steps over and over again. Use a background to log in as an admin, create users, create groups and all the prerequisites you need to test as that user.
- Backgrounds are used when you have multiple scenarios on the page that use the same prerequisites. For example, both scenarios need 4 users to be a part of group so they can share pages to the group. The background would be used to create the four users and then group. The scenario steps would then log in and share the a page to the group and then verify that the page was shared.
- Any scenario you then put on the page will follow the same pathway as the background before initiating the scenario, so make sure all scenarios acually need that background.
For an example click the link in the Behat docs above.
Scenarios
Behat docs for Scenarios:[3]
- Scenarios are just describing what you are doing to test the feature. For example, "Creating a Portfolio page" or "Checking only one search box is visible on the homepage".
- You can have multiple scenarios on the page, they should be on the same page if they are relative to each other.
- Scenarios should have the bug numbers on it, if the test is being written from a bug in Launchpad.
For example:
Scenario: Checking only one search box is visible on the homepage (Bug 12341234)
Steps