【问题标题】:PHPUnit runs only from the command line. Why?PHPUnit 只能从命令行运行。为什么?
【发布时间】:2014-02-19 07:47:52
【问题描述】:

我有以下代码:

<?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)

这是为什么呢?我怎样才能让它在浏览器中也能运行?

【问题讨论】:

  • 为什么没有人回答!?我想知道!

标签: command-line phpunit


【解决方案1】:

您可以集成插件以通过本机 Web GUI 运行单元测试:

https://github.com/NSinopoli/VisualPHPUnit

【讨论】:

    【解决方案2】:

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

    如果要查看代码覆盖率运行

    phpunit --coverage-html=coverage testcase.php
    

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

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

    【讨论】:

      【解决方案3】:

      您可能在命令行上有不同的包含路径。检查除了正常的php.ini 文件之外,您是否还有php-cli.ini 文件。当您从命令行运行 PHP 时,将使用第一个。这可能有不同的include_path 设置。它可能包括 PEAR 目录,例如,如果 PHPUnit 是通过 PEAR 安装的。

      【讨论】:

        【解决方案4】:

        您也可以使用 eclipse 来运行 phpunit。 请点击以下链接

        http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit

        【讨论】:

          猜你喜欢
          • 2010-10-21
          • 2016-04-18
          • 2012-02-14
          • 2016-05-04
          • 2015-08-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-01-01
          相关资源
          最近更新 更多