如何PHPUnit在Netbeans上测试Yii中的组功能?

时间:2012-03-16 02:34:35

标签: php unit-testing netbeans yii phpunit

当我在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)
        );
    }     
}

1 个答案:

答案 0 :(得分:2)

要在NetBeans中使用测试组,您需要确保为项目正确配置了设置。确保使用组符号@group group-name正确注释测试。然后在项目属性中,确保选中测试组的复选框。

© 2012, Oracle Corporation and/or its affiliates

然后,当您运行测试时,您将看到一个包含所选组的对话框弹出窗口。

© 2012, Oracle Corporation and/or its affiliates

如果在按Ctrl+F6时没有看到上面的对话框,请尝试右键单击该文件并选择Test。有关详细信息,请参阅Netbeans PHPUnit documentation