【问题标题】:PHPUnit: Running tests from instancesPHPUnit:从实例运行测试
【发布时间】:2013-10-29 08:33:17
【问题描述】:

我想知道是否有办法从一个对象运行 PHPUnit 测试。示例

<?php

class FooTest extends PHPUnit_Framework_TestCase{

   public function testTrue(){
     $this->assertTrue(true);
   }

}

然后在另一个 PHP 文件中:

<?php

$test = new FooTest;

// function to run $test->testTrue();

这可能吗?谢谢。

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    是的,这是可能的。可以这样做:

    $test = new FooTest();
    $results = $test->run();
    

    当您创建测试时,您正在扩展 PHPUnit_Framework_TestCase。 PHPUnit 在每个测试中调用run 方法。因此,您可以在测试中自己调用它来运行它。此方法返回一个 PHPUnit_Framework_TestResult,您可以使用它来查看测试结果。

    查看PHPUnit source code 了解有关不同对象的更多信息。

    【讨论】:

    猜你喜欢
    • 2013-08-17
    • 1970-01-01
    • 2015-06-26
    • 2015-08-15
    • 1970-01-01
    • 2015-06-15
    • 2017-10-19
    • 2014-07-21
    • 2019-10-05
    相关资源
    最近更新 更多