/
PHPUnit test case dependency
PHPUnit test case dependency
목표
단위 테스트를 할때 테스트케이스들을 순서대로 실행해야 하는 경우가 있습니다.
예로 사용자를 삭제하는 테스트 케이스전에 사용자를 등록하는 테스트 케이스를 실행해야겠죠.
@depends annotation
PHPUnit 은 이런 테스크 케이스간의 의존성을 위해 @depends annotation 을 제공하고 있습니다.
사용법은 다음과 같이 의존성있는 메서드를 기술해 주면 되며 아래의 코드는 testAddUser 가 testDelUser 보다 먼저 실행됩니다.
public function testAddUser() { $ar = ['name' => 'KwangSeob', 'email' => 'lesstif@gmail.com']; $user = User::create($ar); return $user; } /** * @depends testAddUser */ public function testDelUser(User $user) { $this->assertEquals('KwangSeob', $user->name); $this->assertNotEmpty($user->id); return $user; }
@depends 사용시 이전 테스트의 리턴값은 다음 테스트의 입력값으로 사용할 수 있습니다.
즉 testAddUser 에서 리턴한 $user 는 testDelUser 의 입력값으로 전달되므로 테스트 케이스간에 자료를 전달하여 더욱 유연한 테스트를 만들 수 있습니다.
Ref
- https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html
- https://phpunit.de/manual/current/en/appendixes.annotations.html
, multiple selections available,
Related content
PHPUnit 에서 예외 테스트(Exception Test) 하기
PHPUnit 에서 예외 테스트(Exception Test) 하기
More like this
phpunit 설치 및 php 단위 테스트 하기
phpunit 설치 및 php 단위 테스트 하기
More like this
laravel test 하기
laravel test 하기
More like this
phpunit Fixtures
phpunit Fixtures
More like this
phpunit 단위 테스트 건너뛰기(skipping tests)
phpunit 단위 테스트 건너뛰기(skipping tests)
More like this
hamcrest 로 가독성있는 jUnit Test Case 만들기
hamcrest 로 가독성있는 jUnit Test Case 만들기
More like this