当我在Netbeans中使用PHPUnit测试框架Yii时,我遇到了问题。
我有一个类DemoController.php从Yii类Controller扩展。我有一个类DemoControllerTest.php。
我可以通过PHPUnit测试类中的所有函数,但是当我使用@group annotation
(由PHPUnit支持)来测试组函数时。 它没有运行。
DemoController.php:
class DemoController extends Controller {
public function add($a, $b)
{
return $a + $b;
}
}
DemoControllerTest.php:
require_once dirname(__FILE__) . '/../fixtures/dataProvider.php';
require_once dirname(__FILE__) . '/../controllers/DemoController.php';
class DemoControllerTest extends PHPUnit_Framework_TestCase{
protected $object;
protected function setUp() {
$this->object = new Calculator;
}
/**
* @group Calculator
*
* @dataProvider dataProvider
*/
public function testCalculator($expectValue, $inputA, $inputB) {
$this->assertEquals($expectValue, $this->object->add($inputA, $inputB));
}
function dataProvider(){
$result = dataProvider::dataProvider();
return $result;
}
}
这是dataProvider.php:
class dataProvider {
static function dataProvider(){
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 3)
);
}
}
答案 0 :(得分:2)
要在NetBeans中使用测试组,您需要确保为项目正确配置了设置。确保使用组符号@group group-name
正确注释测试。然后在项目属性中,确保选中测试组的复选框。
然后,当您运行测试时,您将看到一个包含所选组的对话框弹出窗口。
如果在按Ctrl+F6
时没有看到上面的对话框,请尝试右键单击该文件并选择Test
。有关详细信息,请参阅Netbeans PHPUnit documentation。