PHPUnit:从实例运行测试



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

<?php
class FooTest extends PHPUnit_Framework_TestCase{
   public function testTrue(){
     $this->assertTrue(true);
   }
}

然后在另一个 PHP 文件中:

<?php
$test = new FooTest;
// function to run $test->testTrue();

这可能吗?谢谢。

是的,这是可能的。 可以这样完成:

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

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

查看 PHPUnit 源代码以获取有关不同对象的更多信息。

最新更新