Program Tip

특정 phpunit xml testsuite를 실행하는 방법은 무엇입니까?

programtip 2020. 10. 21. 21:18
반응형

특정 phpunit xml testsuite를 실행하는 방법은 무엇입니까?


실행할 특정 테스트 스위트를 어떻게 선택할 수 있습니까?

$ phpunit --configuration config.xml

config.xml :

<testsuites>
    <testsuite name="Library">
        <directory>library</directory>
    </testsuite>
    <testsuite name="XXX_Form">
        <file>library/XXX/FormTest.php</file>
        <directory>library/XXX/Form</directory>
    </testsuite>
</testsuites>

다음은 PHPUnit 3.7.13과 같은 코드입니다.

$ phpunit --configuration config.xml --testsuite Library
$ phpunit --configuration config.xml --testsuite XXX_Form

테스트 스위트 그룹을 실행하려면 다음을 수행 할 수 있습니다.

<testsuites>
  <testsuite name="Library">
    <directory>library</directory>
  </testsuite>
  <testsuite name="XXX_Form">
    <file>library/XXX/FormTest.php</file>
    <directory>library/XXX/Form</directory>
  </testsuite>
  <testsuite name="Both">
    <directory>library</directory>
    <file>library/XXX/FormTest.php</file>
    <directory>library/XXX/Form</directory>
  </testsuite>
</testsuites>

그때

$ phpunit --configuration config.xml --testsuite Both

불행히도 PHPUnit은 현재 이와 같은 중첩 된 테스트 모음을 지원하지 않습니다.

<testsuites>
    <testsuite name="Both">
      <testsuite name="Library">
        <directory>library</directory>
      </testsuite>
      <testsuite name="XXX_Form">
        <file>library/XXX/FormTest.php</file>
        <directory>library/XXX/Form</directory>
      </testsuite>
  </testsuite>
</testsuites>

따라서 이런 방식으로 테스트 스위트 그룹을 실행하려면 xml 구성을 복제해야합니다!


이것은 phpunit-user 메일 링리스트에있는 다음 메시지에 의해 입증 된 것처럼 현재 버전의 PHPUnit에서는 불가능합니다 : http://thread.gmane.org/gmane.comp.php.phpunit.user/1302

그러나 대안이 있습니다. 간단히 phpunit에 경로를 전달할 수 있습니다.

phpunit library/XXX

이것은 library / XXX 디렉토리의 모든 테스트를 실행합니다.

이것이 충분하지 않은 경우 다른 옵션은 @group 주석사용하여 테스트를 선택적으로 실행할 수있는 여러 범주로 나누는 것입니다.


phpunit 6.1부터는 xml config 파일에서 속성을 사용할 수 있습니다 defaultTestSuite. 이것은 기본 옵션을 사용하는 것과 같 phpunit --testsuite xxx으며 무시됩니다.


또 다른 옵션은 개별적으로 테스트하려는 각 테스트 스위트에 대해 별도의 구성 파일을 만드는 것입니다. 중복 설정을 복사 / 붙여 넣기해야하는 오버 헤드가 있지만 필요에 따라 각 구성 파일을 지정할 수 있습니다.


여기에있는 다른 답변은 정확합니다. xml 구성을 사용하여이 작업을 수행 할 수 없지만 php에서 동일한 유형의 구성을 만들 수 있습니다.

확실히 가장 예쁜 것은 아니지만 필요한 기능을 제공해야합니다.

xml 구성을 제공했습니다.

<testsuites>
  <testsuite name="Library">
    <directory>library</directory>
  </testsuite>
  <testsuite name="XXX_Form">
    <file>library/XXX/FormTest.php</file>
    <directory>library/XXX/Form</directory>
  </testsuite>
</testsuites>

Hypothetically, let's say your directory "library" contains 3 files:

library
   XXX    
     FormTest.php
   Unit
     unittest1.php
     unittest2.php

And that each of the files contains 1 test by perfect naming convention, eg: FormTest contains testForm()

For the config we'll create a config that contains everything:

<?php
include_once "library/XXX/FormTest.php";
include_once "library/Unit/unittest1.php";
include_once "library/Unit/unittest2.php";

Then we'll create a class by the phpunit naming conventions. You can name it whatever you want as we'll never actually use it...

class LibraryConfigTest extends PHPUnit_Framework_TestCase {

Each "test suite" will simply be a method that runs the tests you want. Name the methods whatever you want as, once again, we'll never actually use it. Phpunit will take care of the running. Be sure to comment them into groups though so you know how to execute.

/**
 * All Tests in Library
 * @group Library
**/
   public function testLibrary() {
      UnitTest1::testUnit1();
      UnitTest2::testUnit2();
      FormTest::testForm();
   }

/**
 * All Form tests in library/XXX
 * @group XXX_Form
**/
   public function testForm() {
      FormTest::testForm();
   }
 }
 ?>

Now in order to get the functionality you want just run the "config" against the group you want.

phpunit --group XXX_Form library_config.php
phpunit --group Library library_config.php

As I said, this is ugly and certainly not good code as it will require constant maintenance, but it will give you the functionality you're looking for.

Hopefully Bergmann will add this functionality in his next round although it doesn't seem likely as he appears to pretty much be ignoring it.

참고URL : https://stackoverflow.com/questions/3671685/how-to-run-a-specific-phpunit-xml-testsuite

반응형