Actions

Difference between revisions of "Testing Area/Behat Testing/Running test"

From Mahara Wiki

< Testing Area‎ | Behat Testing
m (Anitsirk moved page Testing/Behat Testing/Running test to Testing Area/Behat Testing/Running test: Consolidating where testing pages sit)
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
<h2>Running the test</h2>
 
<h2>Running the test</h2>
  
 +
Go to the terminal and cd into your code directory. If you set it up following the wiki, that will be
 +
  cd code/mahara
  
Type this into the terminal from '''any directory''':
+
The command for running tests consists of a helper script which takes two arguments:  
mahara_behat run @tag
+
the mode you want to run in and the test/s you want to run.
  
The tag is whatever you have tagged your test to be. For example:
+
  ./test/behat/mahara_behat.sh <''mode''> <''test/s''>
mahara_behat run @core_page
+
 
 +
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:
 +
 
 +
<source>./test/behat/mahara_behat.sh run create_page.feature html</source>
  
 
When you run the command it will start up the following:
 
When you run the command it will start up the following:
Line 12: Line 33:
 
  Start the PHP server
 
  Start the PHP server
 
  Enable test site
 
  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/
 +
 +
<h2>Test failing</h2>
  
 
* If another test runs instead, it's because you have more than one test tagged with the tag you are trying to run.
 
* 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.
 
* 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]]

Revision as of 14:05, 8 June 2020

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 which 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

  • 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.