[php] PHPunit에서 테스트를 건너 뛰는 방법?

젠킨스와 관련하여 phpunit을 사용하고 있으며 XML 파일에서 구성을 설정하여 특정 테스트를 건너 뛰고 싶습니다. phpunit.xml

명령 줄에서 사용할 수 있다는 것을 알고 있습니다.

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

<filters>태그가 코드 커버리지 전용 이므로 XML 파일로 어떻게 변환 합니까?

다음을 제외한 모든 테스트를 실행하고 싶습니다. testStuffThatAlwaysBreaks



답변

중단되었거나 나중에 작업을 계속해야하는 테스트를 건너 뛰는 가장 빠르고 쉬운 방법은 개별 단위 테스트의 맨 위에 다음을 추가하는 것입니다.

$this->markTestSkipped('must be revisited.');


답변

전체 파일을 무시할 수 있다면

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>

    <testsuites>
        <testsuite name="foo">
            <directory>./tests/</directory>
            <exclude>./tests/path/to/excluded/test.php</exclude>
                ^-------------
        </testsuite>
    </testsuites>

</phpunit>


답변

때로는 PHP 코드로 정의 된 사용자 정의 조건에 따라 특정 파일에서 모든 테스트를 건너 뛰는 것이 유용합니다. makeTestSkipped도 작동하는 setUp 함수를 사용하여 쉽게 할 수 있습니다.

protected function setUp()
{
    if (your_custom_condition) {
        $this->markTestSkipped('all tests in this file are invactive for this server configuration!');
    }
}

your_custom_condition 은 정적 클래스 메소드 / 속성, phpunit 부트 스트랩 파일에 정의 된 상수 또는 전역 변수를 통해 전달할 수 있습니다.


답변