如何在phpunit中运行目录结构化的测试?

3
PHPUnit文档中提到我可以将所有测试放在一个文件夹中,然后运行phpunit来一次性执行它们: http://www.phpunit.de/manual/current/en/organizing-tests.html 但是当我在我的forked复制版Slim上尝试时,它却不起作用! 我已经通过PEAR安装了PHPUnit,所以我认为没有什么奇怪的地方。
以下是输出:
mark@ubuntu:/project/submodules/Slim$ phpunit tests     
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "tests.php" nor "tests.php" could be opened.' in /usr/share/php/PHPUnit/Util/Skeleton/Test.php:102
Stack trace:
#0 /usr/share/php/PHPUnit/TextUI/Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('tests', '')
#1 /usr/share/php/PHPUnit/TextUI/Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#2 /usr/bin/phpunit(49): PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in /usr/share/php/PHPUnit/Util/Skeleton/Test.php on line 102

有什么想法我做错了吗?

-编辑-

我正在使用PHPUnit 3.5.15。

这里是目录 Slimtests 的内容:

mark@ubuntu:/project/submodules/Slim$ ls -l 
total 20
-rw-r--r-- 1 mark mark 4320 Aug 23 14:41 README.markdown
drwxr-xr-x 1 mark mark  408 Aug 24 02:39 Slim
-rw-r--r-- 1 mark mark 6993 Aug 23 14:41 index.php
-rw-r--r-- 1 mark mark 1398 Aug 23 14:41 logo.png
drwxr-xr-x 1 mark mark  476 Aug 23 14:41 tests
mark@ubuntu:/project/submodules/Slim$ ls -l tests
total 104
-rw-r--r-- 1 mark mark    73 Aug 23 14:41 Foo.php
drwxr-xr-x 1 mark mark   204 Aug 23 14:41 Http
-rw-r--r-- 1 mark mark  4398 Aug 23 14:41 LogTest.php
-rw-r--r-- 1 mark mark  5088 Aug 23 14:41 LoggerTest.php
-rw-r--r-- 1 mark mark   734 Aug 23 14:41 README
-rw-r--r-- 1 mark mark 11115 Aug 23 14:41 RouteTest.php
-rw-r--r-- 1 mark mark 10327 Aug 23 14:41 RouterTest.php
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 Session
-rw-r--r-- 1 mark mark 47703 Aug 23 14:41 SlimTest.php
-rw-r--r-- 1 mark mark  6447 Aug 23 14:41 ViewTest.php
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 logs
drwxr-xr-x 1 mark mark   102 Aug 23 14:41 templates

我刚刚fork了Slim并克隆了它,没有什么花里胡哨的东西!

你能粘贴Slimtests文件夹的内容吗? - David Harkness
可以运行。那是哪个PHPUnit版本? - netcoder
这是PHPUnit v3.5.15版本。我将编辑问题以包括文件夹的内容。谢谢! - Mark Stickley
2个回答

2

通常,你需要在包含 phpunit.xml 和/或 bootstrap.php 的文件夹中执行 phpunit 命令。 我猜这些文件位于 tests 文件夹内。

.../Slim$ cd tests
.../Slim/tests$ phpunit

谢谢!我已经添加了目录内容,但是在tests文件夹中没有phpunit.xmlbootstrap.php。有什么想法吗?Slim文档说我只需要从Slim目录内运行phpunit tests就可以了... - Mark Stickley
你尝试过在“tests”目录中运行上述命令吗? - David Harkness
我做了,是的,但它不起作用 :( - Mark Stickley

2
原来这个错误是因为你指定了一个文件夹,但该文件夹中没有任何与模式*Test.php匹配的文件。但是这不是我的问题。我正在使用VirtualBox内部的共享文件夹在Ubuntu虚拟机中运行测试。显然这与PHPUnit不兼容,或者可能是PHP的问题。无论哪种情况,它都会错误地报错,因为当我将文件夹移动到虚拟机内的非共享位置时,它就可以正常工作了。
编辑:我之前使用的是VirtualBox 4.1.0,它显然存在这个问题。升级到4.1.2后问题得到解决,现在一切都正常运行。感谢大家的帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接