我在项目中使用 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.
最佳答案
看看 Appendix for your PHPUnit config file .您可以告诉 PHPUnit 要包含哪些文件夹:
<testsuites>
<testsuite name="Submodules">
<directory suffix="Test.php">../lib/*</directory>
</testsuite>
</testsuites>
当您运行它时,PHPUnit 应该递归地遍历 lib 中的所有文件夹,并将所有以 Test.php 结尾的文件视为单元测试。测试套件的名称无关紧要。为了简化 XML 文件的创作,consider using my phpunit-schema file .
在 PHPUnit Manual Chapter: Composing a Test Suite Using the Filesystem 中有一些额外的信息.Netbeans 有一个 input dialog in which you can specify the path to the phpUnit.xml and any custom TestSuite Class.
这是一个示例项目: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
关于php - 测试多个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5500558/