Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Writing new acceptance test step definitions

From MoodleDocs
Revision as of 21:20, 25 April 2019 by Eloy Lafuente (stronk7) (talk | contribs) (→‎See aslo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

As well as using the already existing steps described in Writing acceptance tests, you can also define new steps.

This is most easily learned by looking at the examples that are already in the code. In any plugin, for example qtype_ddwtos, look at the file tests/behat/behat_qtype_ddwtos.php inside that plugin. Steps are defined by a function that has a special @Given, @When or @Then annotation in the PHPdoc comment. This gives a regular expression. Any step in a *.feature file which matches that regular expression will be translated into a call to that function.

In terms of making the Behat test work, it does not matter whether you use @Given, @When or @Then. However, to make your step understandable to people using your step, it is important to use the right word. Use @Given for steps that set things up, @When for steps that perform actions, and @Then for steps that verify what happened.

When defining new Step definitions in your plugin, try to make sure the step name identifies it as belonging to your plugin. So, don't make a step called I disable UI plugins. Call it something like I disable UI plugins in the CodeRunner question type.

See also