1

在 cmdline 中一切正常:

d:\xampp\htdocs\PhpProject1\Tests>phpunit TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 2.75Mb

OK (1 test, 1 assertion)

在 NetBeans7.1 中调用:

Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBeansSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123

我认为这是一个 NetBeans 问题。如果我运行:

d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 2.75Mb

OK (1 test, 1 assertion)

没关系。但是如果我给出测试目录,它就会失败。

d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\

Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBea
nsSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123

有什么临时解决办法吗?

4

1 回答 1

3

当针对单个文件运行 PHPUnit 时,它总是会打开文件并在其中查找测试用例。

当针对目录运行它时(netbeans 所做的),它只会查看以结尾的文件*Test.php(除非在 phpunit.xml 中指定了其他内容)。

如果找不到任何测试,它将尝试查看$TestSuiteName文件夹和{$TestSuiteName}.php文件,因此会出现错误消息:

致命错误:未捕获的异常 'PHPUnit_Framework_Exception' 带有消息“找不到类”

因为它正在寻找 netbeans phpunit 工具中的“未命名”测试套件。错误消息真的没有帮助你:)

一般的建议是创建一个phpunit.xml并将 Netbeans 指向它。

更个人的一点是:从主要 IDE 中的 phpunit 支持来看,Netbeans 做了很多正确的事情,并且对很多人都很好,所以如果你想要的话,不要让这个碰撞阻止你从 IDE 中使用它.

于 2012-02-27T08:43:38.083 回答