Search code examples
phpunit-testingphpunit

Run PHPUnit Tests in Certain Order


Is there a way to get the tests inside of a TestCase to run in a certain order? For example, I want to separate the life cycle of an object from creation to use to destruction but I need to make sure that the object is set up first before I run the other tests.


Solution

  • Maybe there is a design problem in your tests.

    Usually each test must not depend on any other tests, so they can run in any order.

    Each test needs to instantiate and destroy everything it needs to run, that would be the perfect approach, you should never share objects and states between tests.

    Can you be more specific about why you need the same object for N tests?