codeception 基础使用[简译]
来源:互联网 发布:手机淘宝店怎么改头像 编辑:程序博客网 时间:2024/05/28 19:24
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();
当我们使用 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
0 0
- codeception 基础使用[简译]
- CodeCeption -- 使用
- Yii2中如何使用CodeCeption
- CodeCeption -- 初探
- codeception快速入门
- codeception的Module们
- reference for codeception
- Codeception API testing
- debug codeception in Eclipse
- codeception 运行testcase 的方式
- YII2中Codeception的安装
- PHP 行为测试工具 Codeception 介绍
- swagger + codeception 测试自动化落地方案
- PHP 行为测试工具 Codeception 介绍
- 利用codeception过程中遇到的问题及解决方式
- MYSQL的基础使用
- NUnit使用基础
- log4j基础与使用
- Trie树
- Java俄罗斯方块代码(转载)
- java intelliJ eclipse 配置文件处理的一点区别
- Java中httpClient中的设置超时时间
- 个人日常资料整理
- codeception 基础使用[简译]
- IOS开发指南读书笔记10(IOS数据持久层的建立2)
- ShortCut的延伸功能--为一个app的不同界面创建不同的快捷方式
- 解构推荐系统:“猜你喜欢”是怎么猜中你的心思
- EasyUI中将DateBox的默认值设置成yyyy-mm-dd格式
- OpenCV成长之路(9):特征点检测与图像匹配
- Spinner实现下拉框
- 生成可重集排列
- HDU ACM 2111 Saving HDU