Order of execution of test cases in PHPUnit

I defined a list of test files that should be executed in order in phpunit.xml.

According to http://phpunit.de/manual/3.7/en/organizing-tests.html#organizing-tests.xml-configuration it is mentioned that the order of the test case can be defined as:

<phpunit> <testsuites> <testsuite name="Object_Freezer"> <file>Tests/Freezer/HashGenerator/NonRecursiveSHA1Test.php</file> <file>Tests/Freezer/IdGenerator/UUIDTest.php</file> <file>Tests/Freezer/UtilTest.php</file> <file>Tests/FreezerTest.php</file> <file>Tests/Freezer/StorageTest.php</file> <file>Tests/Freezer/Storage/CouchDB/WithLazyLoadTest.php</file> <file>Tests/Freezer/Storage/CouchDB/WithoutLazyLoadTest.php</file> </testsuite> </testsuites> </phpunit> 

But, since PHPUnit ignores the configuration in phpunit.xml and runs the test cases in alphabetical order.

I want to determine the order only because I want one of my test cases to run at the end. Below is my code:

 <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true" stopOnFailure="false" forceCoversAnnotation="true" bootstrap="../application/third_party/CIUnit/bootstrap_phpunit.php"> <testsuites> <testsuite name="ModelTests"> <directory suffix=".php">models</directory> <file>./models/aa.php</file> <file>./models/bb.php</file> <file>./models/cc.php</file> <file>./models/dd.php</file> <file>./models/ab.php</file> <file>./models/ac.php</file> </testsuite> </testsuites> <filter> <whitelist addUncoveredFilesFromWhitelist="true"> <directory suffix=".php">models</directory> </whitelist> </filter> </phpunit> 

when I execute phpunit it prints: The configuration is read from /var/www/builds/latest/tests/phpunit.xml

Any idea?

+7
php phpunit
source share
1 answer

You need to say that phpunit uses the test suite so that it runs the tests in the correct order. I assume you are just using phpunit . or something similar to run tests. In this case, PHPUnit loads the tests and runs them in a rather random manner. To use the order you specify, you need to do phpunit --testsuite ModelTest . This tells PHPUnit to use the order specified in the package.

However, it will also run tests listed in XML, so make sure your list is exhaustive.

Also, as stated in the related answer in the comments, if your tests should be run in a specific order, this is not an ideal situation. You should try either to change the design or your tests so that you are not dependent on running them in a certain order.

+2
source share

All Articles