Reputation: 283043
I know there is an option in PHPUnit to stop-on-failure
but I don't want it to stop when any test fails, just when this specific test fails.
For example, in my setUp
I connect to a DB, and in the first test I check if it connected to the correct DB. If that fails, I can't run the rest of the tests.
Upvotes: 0
Views: 634
Reputation: 70893
Use the @depends
feature of PHP.
If a test depends on another, it will only be executed if that other test succeeded. Otherwise it will be skipped. This allows you to pinpoint problems better.
Usage: Add a PHPDOC block at the top of the test function that should only be executed when the other test is successful, and add a line @depends testConnectToDb
.
See http://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.depends and http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.test-dependencies for some more details.
Upvotes: 1