9

I have defined the list of the Test files which needs to be executed in a order in phpunit.xml.

As per http://phpunit.de/manual/3.7/en/organizing-tests.html#organizing-tests.xml-configuration it is mentioned that 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 as it seems like PHPUnit is ignoring the config in phpunit.xml and executing the test cases in alphabetical order.

I want to define order just because I want one of my test case to be executed 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: Configuration read from /var/www/builds/latest/tests/phpunit.xml

Any idea?

DShah
  • 472
  • 5
  • 15

1 Answers1

3

You need to tell phpunit to use the test suite so that it is running the tests in the proper order. I am guessing that you are just using phpunit . or something similar to run the tests. In this case, PHPUnit loads up the tests and runs them in a pretty random fashion. In order to use the order that you are specifying you need to do phpunit --testsuite ModelTest This tells PHPUnit to use the order that are specifying in the suite.

However, it also will only run the tests listed in the XML there, so make sure that your list is comprehensive.

Also, as mentioned in the linked answer in the comments, having your tests be required to be run in a certain order isn't an ideal situation. You should try to either change your design or your tests so that you are not dependent on them being run in a certain order.

Schleis
  • 41,516
  • 7
  • 68
  • 87
  • @DShah what version of PHPUnit are you running? The command works fine for me with 3.7 – Schleis Apr 04 '14 at 11:27
  • Version is 3.6.10, I will check again for 3.7. Actually I have installed PHPUnit in ubuntu using sudo apt-get install phpunit. And that installs 3.6.10 version only. – DShah Apr 04 '14 at 11:31