PHPUnit的3.6.10 + 7.1的NetBeans:好的测试抛出异常

PHPUnit的3.6.10 + 7.1的NetBeans:好的测试抛出异常

问题描述:

在CMDLINE一切正常:PHPUnit的3.6.10 + 7.1的NetBeans:好的测试抛出异常

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 

任何临时解决方案?

+0

“d:\ Program Files(x86)\ NetBeans 7.1 \ php \ phpunit \ NetBeansSuite.php”中的Grrr .. line 118显示了解决方案 'return self :: rglob(“* [Tt] est.php” ,$ run.DIRECTORY_SEPARATOR);' 测试文件名必须结束... Test.php – shuttle 2012-02-25 11:35:53

+1

您是否已将NetBeans指向您的'bootstrap.php'和/或'phpunit.xml'文件? – 2012-02-25 20:25:35

+0

我个人发现,NetBeans中的PHPUnit支持充其量是有问题的,并且抛弃了它,而是倾向于在命令行上运行单元测试。 – Hades 2012-02-25 12:06:11

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

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

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

Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class ""

,因为它正在寻找一个“未命名”测试套件中netbeans phpunit线束。错误信息真的不帮你:)

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

在更个人的观点上:从主要IDE中的phpunit支持Netbeans做了很多事情,对很多人来说工作得很好,所以不要让这个不愉快的事情阻止你从IDE使用它if那就是你想要的。