【问题标题】:PHPUnit Testing Error : The system cannot find the path specifiedPHPUnit 测试错误:系统找不到指定的路径
【发布时间】:2013-10-26 03:13:13
【问题描述】:

我已经通过 Pear 安装了 PHPUnit。

当我尝试通过 PHPUnit 进行测试时,即使给出了测试文件路径,它也会显示错误: 系统找不到指定的路径。

我尝试过以下示例代码: https://netbeans.org/kb/docs/php/phpunit.html?print=yes#installing-phpunit

<?php
class Calculator
{
    /**
     * @assert (0, 0) == 0
     * @assert (0, 1) == 1
     * @assert (1, 0) == 1
     * @assert (1, 1) == 2
     * @assert (1, 2) == 4
     */
    public function add($a, $b)
    {
        return $a + $b;
    }
}
?>

【问题讨论】:

    标签: phpunit


    【解决方案1】:

    不确定您的源文件叫什么,但没有为该类编写任何测试。您使用了生成器,它创建了@asserts。现在,您需要生成测试类来使用它们。然后需要运行PHPUnit Manual Skeleton Generator 来生成实际测试。

    使用您的代码,您可以轻松生成测试用例的示例@assert 注释。因此,您需要生成测试用例。

    phpunit-skelgen --test Calculator
    

    或用于命名空间(其中 Project 是命名空间)

    phpunit-skelgen --test -- "project\Calculator" Calculator.php
    

    然后你就可以看到生成的测试了

    /**
     * Generated from @assert (0, 0) == 0.
     */
    public function testAdd() {
        $o = new Calculator;
        $this->assertEquals(0, $o->add(0, 0));
    }
    

    最后,你可以执行你的测试了:

     phpunit --bootstrap Calculator.php --verbose CalculatorTest
    

    【讨论】:

      猜你喜欢
      • 2020-05-27
      • 2017-02-05
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 2020-06-24
      • 1970-01-01
      相关资源
      最近更新 更多