I just started using Codeception after years of writing unit tests in plain PHPUnit
. One thing that is bugging me, that I can't find a way to control the order in which the tests are invoked.
In pure old PHPUnit
I was building the test structure manually like this:
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTest('MyFirstTest');
$suite->addTest('MySecondTest');
and the test would be invoked in the order which they were added to the suite. Codeception
on the other hand seems to be iterating through directories and running every test it can find.
I would like to be able to control the order of the tests on two levels:
unit tests
before acceptance tests
)PHPUnit
builds suites)Ad. 2: Let's say I have two tests in acceptance
directory:
AbcCept.php
WebGuy.php
XyzCept.php
I want to be able to run the XyzCept.php
before AbcCept.php
. Is this even possible?
And to anticipate picky comments: yes, I know that tests should be able to run in any order, and not depend on each other, but that's not what I'm asking.
The codeception library is built on top of phpunit, so to skip test there is a function markTestSkipped . Every code after this function will not be executed. It is good to add message explaining why test was skipped. Skipped tests will be marked with capital letter S .
Codeception is very flexible framework that you can use to write your Selenium tests.
Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.
For the ones who are searching for a proper solution and bump into this issue.
I believe, what you truly want to achieve, is that a specific test ran before another test. The order itself is probably not that important. In order to do that, you can add the @dependency
annotation to a test.
Full documentation can be found here: https://codeception.com/docs/07-AdvancedUsage#Dependencies.
Example:
class ModeratorCest {
public function login(AcceptanceTester $I)
{
// logs moderator in
}
/**
* @depends login
*/
public function banUser(AcceptanceTester $I)
{
// bans user
}
}
Files get sorted by name (I assume we are talking about files from the same directory). In other words if you need to run the test XyzCept.php
before AbcCept.php
you re-name the XyzCept.php
to, let's say, AazCept.php
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With