Actions

Testing Area/Behat Testing/Running test: Difference between revisions

From Mahara Wiki

< Testing Area‎ | Behat Testing
No edit summary
(syntax highlight)
 
Line 27: Line 27:
To run tests with html output, add the flag 'html' to your test run command, e.g:
To run tests with html output, add the flag 'html' to your test run command, e.g:


<source>./test/behat/mahara_behat.sh run create_page.feature html</source>
<syntaxhighlight lang="bash">./test/behat/mahara_behat.sh run create_page.feature html</syntaxhighlight>


When you run the command it will start up the following:
When you run the command it will start up the following:
Line 38: Line 38:


To see a list of all tests, cd to your Mahara directory and run:
To see a list of all tests, cd to your Mahara directory and run:
grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/
<syntaxhighlight lang="bash">grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/</syntaxhighlight>


<h2>Test failing</h2>
<h2>Test failing</h2>
Line 47: Line 47:
* The step that the test is failing on will show red or orange.
* The step that the test is failing on will show red or orange.
* When it fails, go to the text editor and fix the step that it broke on and run it again.
* When it fails, go to the text editor and fix the step that it broke on and run it again.


[[Category:Behat]]
[[Category:Behat]]

Latest revision as of 15:22, 25 February 2022

Running the test

Go to the terminal and cd into your code directory. If you set it up following the wiki, that will be

 cd code/mahara

The command for running tests consists of a helper script that takes two arguments: the mode you want to run in and the test/s you want to run.

 ./test/behat/mahara_behat.sh <mode> <test/s>

The options for mode are:

run - runs the selected tests in a local browser
rundebug - runs the selected tests in a local browser and outputs additional debug info in the terminal
runheadless - runs the selected tests without opening a browser
rundebugheadless - runs the selected tests without opening a browser, but with additional debug info in the terminal

The second argument is optional. If you don't include one, all the tests will be run, but this will take a l-o-n-g time! So to only run specific tests, include a tag (e.g. @mytests) to run all the tests with that tag, or a feature file name (e.g. my_test.feature) to run the test scenarios in that file.

A couple of specific examples:

./test/behat/mahara_behat.sh rundebug @core_account

(runs all the tests in feature files tagged @core_account, using a browser, with debug output)

./test/behat/mahara_behat.sh runheadless change_account_settings.feature 

(runs just the change_account_settings test, browserless, without additional debug info)

To run tests with html output, add the flag 'html' to your test run command, e.g:

./test/behat/mahara_behat.sh run create_page.feature html

When you run the command it will start up the following:

Selenium is running
Start the PHP server
Enable test site

If you want to stop the tests at any point click inside the terminal not the browser

 Crtl+c

To see a list of all tests, cd to your Mahara directory and run:

grep -RiPoh 'Scenario:(\s+)\K(.*)$' test/

Test failing

Note: check that your local config is the same as the default config e.g. $cfg->usepdfexport should not be true or exist for for the feature files to find what it needs to (You need chrome-php will not appear if your config is true already);

  • If another test runs instead, it's because you have more than one test tagged with the tag you are trying to run.
  • The step that the test is failing on will show red or orange.
  • When it fails, go to the text editor and fix the step that it broke on and run it again.