Reputation: 1476
Let's assume I have the following files, each of them containing a class that extends my TestCase
:
- Tests
- Feature
...
-Integration
...
- Unit
- ModelTest.php
- BillModelTest.php
- ProductModelTest.php
- CustomerModelTest.php
I'm indifferent as to the order the specific model tests run in, but I would like the ModelTest
to run first (to be clear, ModelTest.php
tests generic model behaviour and built-in methods, while the other tests run tests that are specific to that model).
None of these tests actually depend on each other, so it's not a big issue if they run in whatever they choose - but if a test is going to fail because the base Model's getById()
method is failing, I'd rather catch that in the test for that method, than in an unrelated test that assumes getById()
works as expected.
So far, I've thought of two possible solutions:
Put ModelTest.php
in its own Test Suite. I don't like this solution because a) I don't want to make a bunch of granular test suites if I run into this issue frequently, and b) if I just want to run my Unit Test
suite I would actually need to run two test suites instead, and frankly, ModelTest.php
doesn't belong in a separate test suite, it's a unit test.
Change the file name so that it alphabetically runs first. This one is more acceptable to me but I still don't like it as it clutters the filenames and makes the application feel less clean overall.
Is there any other way to ensure that one particular TestCase will run before others?
Upvotes: 1
Views: 34
Reputation: 12365
It shouldn't matter.
If you are generating code coverage reports when running PHPUnit, you will see that it tells you how many of your tests actually called that code.
So don't worry about it!
Upvotes: 1