我有一个类似于这样的PHPUnit测试:
/**
* @dataProvider provideSomeStuff
*/
public function testSomething($a, $b, $c)
{
...
}
/**
* @dataProvider provideSomeStuff
* @depends testSomething
*/
public function testSomethingElse($a, $b, $c)
{
...
}
/**
* @depends testSomething
*/
public function testMoreStuff()
{
...
}
// Several more tests with the exact same setup as testMoreStuff
即使testSomething
成功了,所有依赖它的测试都会被跳过。PHPUnit手册中的一些注释提示,测试可以依赖于使用数据提供程序的其他测试:
Note 当测试同时接收来自@dataProvider方法的输入以及它所依赖的一个或多个测试时,来自数据提供程序的参数将先于依赖测试的参数。 Note 当测试依赖于使用数据提供程序的测试时,当它所依赖的测试至少对一个数据集成功时,将执行依赖测试。不能将使用数据提供程序的测试结果注入到依赖的测试中。
所以我不知道为什么它会跳过我所有的测试。我已经挣扎了好几个小时了,谁来帮帮我。如果不能从上面的伪代码导出问题,请使用这是完整的测试代码。
测试结果的截图:
发布于 2012-06-16 19:32:07
这似乎是phpunit 3.4.5中的一个bug,但是修复了phpunit 3.4.12中的错误。
下面是一个很小的例子,基于手册中的例子。在PHPUnit 3.4.5中,我得到了与您相同的行为,但在PHPUnit 3.6.11中获得了4次及格。缩小范围后,phpunit 3.4变更量g说它是在PHPUnit 3.4.12中修正的。
class DataTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider provider
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}
/**
* @depends testAdd
*/
public function testAddAgain()
{
$this->assertEquals(5,3+2);
}
/** */
public function provider()
{
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
);
}
}
发布于 2015-12-29 12:19:53
必须在主方法之后定义依赖方法。
public function testSomething()
{
$foo = [];
//test something
return $foo;
}
/**
* @depends testSomething
*/
public function testBar(array $foo)
{
//more tests
}
https://stackoverflow.com/questions/11051020
复制相似问题