codeception 基础使用[简译]

7 篇文章 0 订阅
codeception 基础使用[简译]
当我们使用 codeception 页面对象代码时,这些代码扩展自 BasePage 类。这样可以减少些重复。yii2-app-basic 和 yii2-app-advanced 里都有。


TestCase 类有一些常见的单元测试功能,如应用创建前测试,消毁后测试。也可以配置应用类。TestCase 类扩展自 Codeception\TestCase\Case ,所有方法和用例都是可用的。你也可以使用 codeception 模块和事件在你的测试代码中。


取得 codeception 模块
如果你要使用 codeception 模块和帮助在你的单元测试中,你要这样做:


<?php
#in your unit-test
$this->getModule('CodeHelper'); #or some other module


你也可以使用 actor 方法:


<?php
$this->unitTester->someMethodFromModule();


Codeception 事件
调用事件:


<?php
use Codeception\Event\TestEvent;


public function testSomething()
{
    $this->fire('myevent', new TestEvent($this));
}


这个事件可以调用模块和帮助。如果你的测试在组中。事件名称后面要跟着写组名,例如:myevent.somegroup。


简单的测试方法


执行测试方法:


tests\unit\models\UserTest::setUpBeforeClass();


    tests\unit\models\UserTest::_before();


        tests\unit\models\UserTest::setUp();


            tests\unit\models\UserTest::testSomething();


        tests\unit\models\UserTest::tearDown();


    tests\unit\models\UserTest::_after();


tests\unit\models\UserTest::tearDownAfterClass();


如果执行简单测试方法不要忘了调用其父类。


原文:https://github.com/yiisoft/yii2-codeception/blob/master/docs/guide/basic-usage.md

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值