다양한 사용자 클래스가 상위 사용자 클래스 , 그렇다면 테스트 케이스 클래스에 대해 동일한 상속 구조를 사용하는 것이 좋습니다. 당신은 당신의 테스트 케이스 클래스로 다음을 수행 할 수
class User
{
public function commonFunctionality()
{
return 'Something';
}
public function modifiedFunctionality()
{
return 'One Thing';
}
}
class SpecialUser extends User
{
public function specialFunctionality()
{
return 'Nothing';
}
public function modifiedFunctionality()
{
return 'Another Thing';
}
}
:
는 다음 샘플 클래스 고려 각 테스트가 재정의 할 수있는 작성 방법에 의존하기 때문에
class Test_User extends PHPUnit_Framework_TestCase
{
public function create()
{
return new User();
}
public function testCommonFunctionality()
{
$user = $this->create();
$this->assertEquals('Something', $user->commonFunctionality);
}
public function testModifiedFunctionality()
{
$user = $this->create();
$this->assertEquals('One Thing', $user->commonFunctionality);
}
}
class Test_SpecialUser extends Test_User
{
public function create() {
return new SpecialUser();
}
public function testSpecialFunctionality()
{
$user = $this->create();
$this->assertEquals('Nothing', $user->commonFunctionality);
}
public function testModifiedFunctionality()
{
$user = $this->create();
$this->assertEquals('Another Thing', $user->commonFunctionality);
}
}
을하고 있기 때문에 테스트 메소드는 부모 테스트 클래스에서 상속받습니다. 부모 클래스에 대한 모든 테스트는 예상 동작을 변경하기 위해 재정의하지 않는 한 하위 클래스에 대해 실행됩니다.
이것은 제한된 경험으로 훌륭하게 작동했습니다.