Voj*_*rka 13 php phpunit testcase
我正在寻找一种如何使用不同的设置多次运行测试用例的方法.
我正在测试一个数据库访问类(几十种测试方法),并希望在"正常模式"下测试它,然后在"调试模式"下测试它.两种模式都必须产生相同的测试结果.
在测试用例设置中是否有可能这样做?或者重写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 function setUp()
{
parent::setUp();
$this->myclass->setOptions('debug', $this->debugLevel);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我认为斯文的答案是正确的。写下您要设置的内容,并给出您需要的测试用例参数,例如:
/**
* @dataProvider forMyTest
*/
public function testWithDifferentDbType($type, $param1, $param ....)
{
$this->assertExists(....);
}
public function forMyTest() {
return [
[
true
[$prodDb, $param1, $param, .....],
],
[
false,
[$debugDb, $param1 $param, ....,
],
];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3184 次 |
| 最近记录: |