PHPUnit 仅从命令行运行。为什么?
我有以下代码:
<?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)
这是为什么?我怎样才能让它在浏览器中运行呢?
I have the following code:
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testCalculate()
{
$this->assertEquals(2, 1 + 1);
}
}
?>
When I open the PHP file in the browser, I get the following error:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
However, if I use the command line it works fine:
phpunit [local_path_here]/testcase.php
Result:
.
Time: 0 seconds, Memory: 5.00Mb
OK (1 test, 1 assertion)
Why is that? How can I make it to run it in the browser as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以集成插件以通过本机 Web GUI 运行单元测试:
https://github.com/NSinopoli/VisualPHPUnit< /a>
You can integrate add-on for running unit tests via native web GUI:
https://github.com/NSinopoli/VisualPHPUnit
您无法在浏览器中运行单元测试。也许将来: http://sebastian-bergmann.de/archives/ 638-PHPUnit-3.0.html#c4983
如果想查看代码覆盖率运行
然后打开覆盖率目录下的index.html文件。
否则,您必须从命令行运行测试。
You can't run unit tests in the browser. Maybe in the future: http://sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983
If you want to view the code coverage run
and then open the index.html file in the coverage directory.
Otherwise, you have to run your tests from the command line.
您可能在命令行上有不同的包含路径。检查除了正常的
php.ini
文件之外是否还有php-cli.ini
文件。当您从命令行运行 PHP 时,将使用第一个。这可能有不同的include_path
设置。例如,如果 PHPUnit 是通过 PEAR 安装的,则它可能包括 PEAR 目录。You may have a different include path on the command line. Check to see whether you have a
php-cli.ini
file in addition to the normalphp.ini
file. The first one will be used when you run PHP from the command line. That's probably got a differentinclude_path
setting. It might include the PEAR directory, for example, if PHPUnit was installed via PEAR.您还可以使用 eclipse 来运行 phpunit。
请点击以下链接
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit
You can use eclipse also to run phpunit.
follow the link below
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit