I would like to introduce dependencies between my unit tests. My very first test determines if the rest of tests should be performed.
I'm aware of the existence of the @unittest
decorator with its conditional skipping method skipIf
. Therefore, my solution can be as easy as introducing a field responsible for keeping information about the first unit test status. With this information, I can decorate remaining unit tests and skip them if the first unit test failed.
However, I feel that this is not the best approach. If you consider more dependencies, then it appears that it is required to maintain a whole structure to keep required information.
I was looking for a built-in feature but I was unable to find anything better.
Update
To make it as clear as possible: I'm looking for the functionality similar to the @depends annotation in the PHPUnit
. For example, the following code creates dependency between the firstTest
a the secondTest
:
/**
* @depends firstTest
*/
public function secondTest()
{
// test body
}
In the above example, the secondTest
is going to be performed if and only if the firstTest
passed.
Well, This SO thread kind of deals with the same question and what it says is kind of true that if it is a real unit test and if your code is well structured then you should not need (in other words : it should not be the case) that one test depends on another.
However, if you absolutely need it and if there is a real solid reason for that, you may look into Proboscis. Seems like it may have (via grouping the tests) something near to what you want.