-
Improvement
-
Resolution: Fixed
-
Trivial
-
3.9.8, 3.9.10, 3.10.5, 3.10.7, 3.11.1, 3.11.3
-
MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE
-
MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE
-
MDL-72173-master -
Throughout Moodle, in Behat tests, we are testing the same things over and over again unnecessarily.
The main offender being "I log in as"
Often I see:
Given I log in as "someuser"
"I log in as" is not a given and it is not a performant way to log a user into moodle as part of a behat test.
A performant step would instead be:
Given I am logged in as "someuser"
Which places the user in the required state without user interaction
Unless there is some reason for actually needing to test a user filling in the log in form and then submitting the form there is absolutely no need for that to happen in a test.
In fact, there should probably be just 1 test in the entirety of Moodle where "I log in as" is used and that test should be specifically to test the log in feature.
This article goes into more detail about the problems of not using "Given" steps correctly.
https://brudinie.medium.com/behat-given-for-the-win-62f24a098888