问题描述
|
我有以下代码:
<?PHP
class MyTest extends PHPUnit_Framework_TestCase
{
public function testCalculate()
{
$this->assertEquals(2,1 + 1);
}
}
?>
在浏览器中打开PHP文件时,出现以下错误:
致命错误:找不到类\'PHPUnit_Framework_TestCase \'
但是,如果我使用命令行,则可以正常工作:
PHPunit [local_path_here] /testcase.PHP
结果:
.
Time: 0 seconds,Memory: 5.00Mb
OK (1 test,1 assertion)
这是为什么?我怎样才能使其在浏览器中运行?
解决方法
您可以通过本机Web GUI集成用于运行单元测试的插件:
https://github.com/NSinopoli/VisualPHPUnit
,您无法在浏览器中运行单元测试。也许将来:http://sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983
如果要查看代码覆盖率运行
phpunit --coverage-html=coverage testcase.php
然后在coverage目录中打开index.html文件。
否则,您必须从命令行运行测试。
,您可能在命令行上具有其他包含路径。检查以查看除正常的php.ini
文件外是否还有php-cli.ini
文件。当您从命令行运行PHP时,将使用第一个。那可能有一个不同的include_path
设置。例如,如果PHPUnit是通过PEAR安装的,则它可能包含PEAR目录。
,您也可以使用eclipse运行phpunit。
请点击以下链接
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit