【问题标题】:How to PHPUnit test a group function within Yii on Netbeans?如何 PHPUnit 在 Netbeans 上的 Yii 中测试组函数?
【发布时间】:2012-04-01 15:08:21
【问题描述】:

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

【问题讨论】:

  • 你使用什么命令来运行你的测试?

标签: php unit-testing netbeans yii phpunit


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-04-02
    • 2013-09-19
    • 1970-01-01
    • 2010-12-29
    • 2020-06-08
    • 2014-02-10
    • 2014-05-26
    • 2011-12-16
    • 2017-01-11
    相关资源
    最近更新 更多