11

私のプロジェクトでは、PHPUnit 3.5.12、netbean 6.9、および git サブモジュールを使用しています。

したがって、私のフォルダーアーキテクチャは次のようになります。

lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/

メインのテスト フォルダー (phpunit_netbean.xml と bootstrap.php を含む) が /tests/ フォルダーにあることを考慮してください。/lib/*/tests/ でもテストを実行するにはどうすればよいですか?

テストスイートを見てきましたが、動作させることができません。これまでのところ、tests/phpunit_netbean.xml ファイルで次の構成を試しました。

<?xml version="1.0"?>
<phpunit
    bootstrap="./bootstrap.php"
    strict="true"
    stopOnError="false"
    stopOnFailure="false"
    stopOnIncomplete="false"
    stopOnSkipped="false"
    colors="false"
    verbose="true"
    >

    <testsuites>
        <testsuite name="modules">
            <directory>../lib/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

そして、Netbean で ALT+F6 を押すと、実行された /tests からのテストしかありません。同じこと:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here

また、私はこれを試しました:

/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.

Could not use "modules" as loader.
4

2 に答える 2

13

PHPUnit 構成ファイルについては、付録を参照してください。含めるフォルダーを PHPUnit に指示できます。

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>

これを実行すると、PHPUnit は lib 内のすべてのフォルダーを再帰的に繰り返し処理し、Test.php で終わるすべてのファイルを UnitTests と見なします。テストスイートの名前は関係ありません。XML ファイルのオーサリングを容易にするために、私の phpunit-schema ファイル の使用を検討してください

PHPUnit マニュアルの章: ファイルシステムを使用したテスト スイートの作成 に、これに関する追加情報がいくつかあります。Netbeans には、phpUnit.xml および任意のカスタム TestSuite クラスへのパスを指定できる入力ダイアログがあります。

サンプル プロジェクトは次のとおりです: https://github.com/gooh/sample

C:\Users\Gordon\Desktop\demo\tests>phpunit --testdox
PHPUnit 3.5.13 by Sebastian Bergmann.

A
 [x] One

B
 [x] One

My
 [x] One
于 2011-03-31T13:31:03.233 に答える
3

テストケースを作成しましょう:

mkdir project
mkdir project/tests
mkdir project/modules/
mkdir project/modules/a/
mkdir project/modules/a/tests/
mkdir project/modules/b/
mkdir project/modules/b/tests/

echo "<?php class MyTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/tests/MyTest.php
echo "<?php class MyTwoTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/a/tests/MyTwoTest.php
echo "<?php class MyThreeTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/b/tests/MyThreeTest.php


tree
.
`-- project
    |-- modules
    |   |-- a
    |   |   `-- tests
    |   |       `-- MyTwoTest.php
    |   `-- b
    |       `-- tests
    |           `-- MyThreeTest.php
    `-- tests
        `-- MyTest.php

すぐ実行すると、それらのフォルダー内のすべてphpunit projectのテストが実行されます。したがって、これ以上の構成は必要ありません。

/src/ フォルダーに *Test.php で終わる lasses がある場合に唯一問題となるのは、そうしなければ、私の知る限り、問題は発生しません。

phpunit project/
PHPUnit 3.5.11 by Sebastian Bergmann.

...

Time: 0 seconds, Memory: 2.75Mb
于 2011-03-31T13:53:07.557 に答える