测试多个文件夹
我在项目中使用 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.
I use PHPUnit 3.5.12, netbean 6.9, and git submodules in my project.
So my folder architecture looks like that:
lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/
Considering that my main test folder (with phpunit_netbean.xml and bootstrap.php) is in the /tests/ folder; How can I be able to run the tests in /lib/*/tests/ too ?
I've look at testsuite, but I'm unable to get it working. So far I've tried the following configuration in my tests/phpunit_netbean.xml file:
<?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>
And when I hit ALT+F6 in Netbean, I only have the tests from /tests that are run. Same thing with:
/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here
Also, I've tried this:
/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.
Could not use "modules" as loader.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看PHPUnit 配置文件的附录。您可以告诉 PHPUnit 要包含哪些文件夹:
当您运行此命令时,PHPUnit 应该递归地迭代 lib 中的所有文件夹,并将所有以 Test.php 结尾的文件视为 UnitTests。测试套件的名称无关紧要。为了简化 XML 文件的创作,考虑使用我的 phpunit-schema 文件。
PHPUnit 手册章节:使用文件系统。 Netbeans 有一个输入对话框,您可以在其中指定 phpUnit.xml 和任何自定义 TestSuite 类的路径。
这是一个示例项目:https://github.com/gooh/sample
Have a look at the Appendix for your PHPUnit config file. You can tell PHPUnit which folders to include:
When you run this, PHPUnit should recursively iterate over all folders in lib and consider all files ending in Test.php as UnitTests. The name of the testsuite is irrelevant. To ease authoring of the XML file, consider using my phpunit-schema file.
There is some additional information to this in the PHPUnit Manual Chapter: Composing a Test Suite Using the Filesystem . Netbeans has an input dialog in which you can specify the path to the phpUnit.xml and any custom TestSuite Class.
Here is an example project: https://github.com/gooh/sample
让我们创建一个测试用例:
如果您现在刚刚运行
phpunit 项目
,它将执行这些文件夹中的所有测试。所以不需要任何进一步的配置。如果您的 /src/ 文件夹中有以 *Test.php 结尾的女孩,唯一可能会困扰您的事情是,如果您不这样做,据我所知,您不会遇到任何问题。
Let's create a testcase:
If you now just run
phpunit project
it will execute ALL the tests in those folders. So no need for any further configuration.The only thing that could bite you if you have lasses in your /src/ folders that end in *Test.php, if you don't do that you will not have any issues as far as i can tell.