我来这篇文章是为了寻找类似的东西。
我有这个测试用例:
/**
* test routing logic (numbers method returns an array of numbers and expected outputs to test)
* @dataProvider numbers
*/
function testRoute($input,$expected)
{
$route = new Route($input,'',false);
$route->route();
$this->assertEquals($expected,$route->routingResult);
}
我的数字方法是这样的:
/**
* read pairs of numbers (input <tab> expected) from tests.input separater by tab
* return an array like this: array(array(number1,expected1), array(number2,expected2), ...)
* provide this array to my tests by returning it
*/
function numbers()
{
$testcases = file('tests.input');
$tests = array();
foreach($testcases as $test_case)
{
list($input,$output) = explode("\t",$test_case,2);
$tests[] = array(trim($input),trim($output));
}
return $tests;
}
你会从 phpunit 得到这样的输出:
Starting test 'RouteTest::testRoute with data set #0 ('8596000000', 'rejected (dp not found)x')'.
F
Starting test 'RouteTest::testRoute with data set #1 ('8596000001', 'rejected (rejected by scheme)')'.
.
Starting test 'RouteTest::testRoute with data set #2 ('8596000003', '1599000003')'.
.
它不会告诉你测试函数的实际结果,除非测试失败,但至少你可以看到所有断言的值。