ProgramingTip

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

bestdevel 2020. 10. 31. 09:58
반응형

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 부트 파일에있는 정의 상수 또는 전역 변수를 통해 사용할 수 있습니다.

참고 URL : https://stackoverflow.com/questions/10239264/how-to-skip-tests-in-phpunit

반응형