PHPUnit: Testdependencies with test from parentclass
So, I've got a little problem with my Unittests. I wrote some basisclasses for different Testcases and I want to uses some prepared test-methods.
i.e.
class ModelTestCase extends PHPUnit_Framework_TestCase {
public function testCreateInstance() { ... }
}
class UserModelTest extends ModelTestCase {
/**
* (at)depends testCreateInstance
*/
public funcion开发者_如何学JAVA testWhatever($model) { ...}
}
Is there any trick to use it as I want or must I really write every test in every class?
It all depends on what you really want to do, your code sample is way too vague to tell that.
One option for you is to create your own setup() method in ModelTestCase (dont forget to call parent::setUp()) and do some initialization in there.
If you want to test only the derived model tests, but not the base class itself, you can declare it as abstract:
abstract class ModelTestCase extends PHPUnit_Framework_TestCase {
public function testCreateInstance() { ... }
}
This worked for me.
精彩评论