PHPUnit仅从命令行运行.为什么?

Gab*_*iel 6 command-line phpunit

我有以下代码:

<?php
    class MyTest extends PHPUnit_Framework_TestCase
    {
        public function testCalculate()
        {
            $this->assertEquals(2, 1 + 1);
        }
    }
?>
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中打开PHP文件时,出现以下错误:

致命错误:找不到类'PHPUnit_Framework_TestCase'

但是,如果我使用命令行它可以正常工作:phpunit [local_path_here] /testcase.php

结果:

.

Time: 0 seconds, Memory: 5.00Mb

OK (1 test, 1 assertion)
Run Code Online (Sandbox Code Playgroud)

这是为什么?如何让它在浏览器中运行呢?

Chr*_*ing 2

您无法在浏览器中运行单元测试。也许将来: http: //sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983

如果你想查看代码覆盖率运行

phpunit --coverage-html=coverage testcase.php
Run Code Online (Sandbox Code Playgroud)

然后打开coverage目录下的index.html文件。

否则,您必须从命令行运行测试。