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



在cmdline中一切正常:

d:xampphtdocsPhpProject1Tests>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.1phpphpunitNetBeansSuite.php".' in D:xamppphpPEARPHPUnitUtilSkeletonTest.php:123
Stack trace:
0 D:xamppphpPEARPHPUnitTextUICommand.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:Program File...')
1 D:xamppphpPEARPHPUnitTextUICommand.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:xamppphpphpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:xamppphpPEARPHPUnitUtilSkeletonTest.php on line 123

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

d:Program Files (x86)NetBeans 7.1phpphpunit>phpunit NetBeansSuite.php run=d:xampphtdocsPhpProject1TestsTestStub.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.1phpphpunit>phpunit NetBeansSuite.php run=d:xampphtdocsPhpProject1Tests
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:Program Files (x86)NetBeans 7.1phpphpunitNetBea
nsSuite.php".' in D:xamppphpPEARPHPUnitUtilSkeletonTest.php:123
Stack trace:
0 D:xamppphpPEARPHPUnitTextUICommand.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:Program File...')
1 D:xamppphpPEARPHPUnitTextUICommand.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:xamppphpphpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:xamppphpPEARPHPUnitUtilSkeletonTest.php on line 123

有什么临时解决方案吗?

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

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

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

致命错误:未捕获异常"PHPUnit_Framework_exception",消息为"找不到类"

因为它正在netbeansphpunit线束中寻找一个"未命名"的测试套件。错误消息真的对你没有帮助:)

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

更私人的一点是:从主要IDE中的phpunit支持来看,Netbeans做了很多正确的事情,对很多人来说都很好,所以如果你想要的话,不要让这种冲击阻碍你从IDE中使用它。

最新更新