phing 和 phpunit +引导程序
如何使用 phing 运行带有引导文件的 PHPUnit 测试套件?
我的应用程序结构:
application/
library/
tests/
application/
library/
bootstrap.php
phpunit.xml
build.xml
phpunit.xml:
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuite name="Application Test Suite">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory
suffix=".php">../library/</directory>
<directory
suffix=".php">../application/</directory>
<exclude>
<directory
suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
那么:
cd /path/to/app/tests/
phpunit
#all test passed
但是如何从 /path/to/app/
目录运行测试?问题是,bootstrap.php
依赖于库和应用程序的相对路径。
如果我运行 phpunit --configuration tests/phpunit.xml /tests ,我会收到一堆文件未找到错误。
如何为 phing
编写 build.xml
文件来以与 phpunit.xml
相同的方式运行测试?
How to run PHPUnit test suite with bootstrap file with phing?
My app structure:
application/
library/
tests/
application/
library/
bootstrap.php
phpunit.xml
build.xml
phpunit.xml:
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuite name="Application Test Suite">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory
suffix=".php">../library/</directory>
<directory
suffix=".php">../application/</directory>
<exclude>
<directory
suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
then:
cd /path/to/app/tests/
phpunit
#all test passed
But how do I run the tests from /path/to/app/
dir? The problem is, that the bootstrap.php
depends on relative paths to library and application.
If I run phpunit --configuration tests/phpunit.xml /tests
I got a bunch of file not found errors.
How do I write build.xml
file for phing
to run the tests the same way phpunit.xml
does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为最好的方法是创建一个小的 PHP 脚本来初始化单元测试,我正在执行以下操作:
在我的 phpunit.xml / bootstrap="./initalize.php"
initalize.php
BaseTest.php
我所有的单元测试都扩展了 BaseTest 类,它的工作方式就像一个魅力。
I Think the best way is to create an small PHP Script to initalize your Unit tests, iam doing the following:
In my phpunit.xml / bootstrap="./initalize.php"
initalize.php
BaseTest.php
All my Unit tests are extending BaseTest Class, it works like a charm.
当您在 Phing 中使用 PHPUnit 任务时,您可以包含引导文件,如下所示:
When you use the PHPUnit tasks in Phing, you can include your bootstrap file like this: