小编Voj*_*rka的帖子

多次运行PHPUnit测试用例

我正在寻找一种如何使用不同的设置多次运行测试用例的方法.

我正在测试一个数据库访问类(几十种测试方法),并希望在"正常模式"下测试它,然后在"调试模式"下测试它.两种模式都必须产生相同的测试结果.

在测试用例设置中是否有可能这样做?或者重写run()方法?我当然不想写两次测试:)

谢谢

编辑:GOT IT!

public function run(PHPUnit_Framework_TestResult $result = NULL)
{
    if ($result === NULL) {
        $result = $this->createResult();
    }

    /**
     * Run the testsuite multiple times with different debug level
     */
    $this->debugLevel = 0;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    $this->debugLevel = 8;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    $this->debugLevel = 16;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    return $result;
}

public …
Run Code Online (Sandbox Code Playgroud)

php phpunit testcase

13
推荐指数
2
解决办法
3184
查看次数

标签 统计

php ×1

phpunit ×1

testcase ×1