Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2.2 KiB

配置测试环境

注意:本章节内容还在开发中

Yii 2 官方兼容 Codeception 测试框架, 你可以创建以下类型的测试:

  • 单元测试 - 验证一个独立的代码单元是否按照期望的方式运行;
  • 功能测试 - 在浏览器模拟器中以用户视角来验证期望的场景是否发生
  • 验收测试 - 在真实的浏览器中以用户视角验证期望的场景是否发生。

Yii 为包括 yii2-basicyii2-advanced 在内的应用模板脚手架提供全部三种类型的即用测试套件。

为了运行测试用例,你需要安装 Codeception 。 一个较好的安装方式是:

For the local installation use following commands:

composer global require "codeception/codeception=2.0.*"
composer global require "codeception/specify=*"
composer global require "codeception/verify=*"

For the global installation you will need to use global directive:

composer global require "codeception/codeception=2.1.*"
composer global require "codeception/specify=*"
composer global require "codeception/verify=*"

如果你从未通过 Composer 安装过全局的扩展包,运行 composer global status 。你的窗口应该输出类似如下:

Changed current directory to <directory>

然后,将 <directory>/vendor/bin 增加到你的 PATH 环境变量中。现在, 我们可以在命令行中全局的使用 codecept 命令了。

Note: global installation allows you use Codeception for all projects you are working on your development machine and allows running codecept shell command globally without specifying path. However, such approach may be inappropriate, for example, if 2 different projects require different versions of Codeception installed. For the simplicity all shell commands related to the tests running around this guide are written assuming Codeception has been installed globally.