codeception (3)在yii2下创建Unit Tests (单元测试)

我们为frontend的登陆建立一个单元测试
图片描述
提示创建成功,路径写也出来了,我们打开看一下这个文件列表
图片描述
打开生成的文件

namespace tests\codeception\frontend;
class ApiLoginTest extends \Codeception\TestCase\Test
{
    /**
     *@var \tests\codeception\frontend\UnitTester
     */
    protected $tester;

    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testMe()
    {
    }
}

其中有一个testMe的公共方法,我们在这个方法里面写一个断言

public function testMe()
{
   $this->assertTrue(2 == 2);
}

运行这个测试,显示ok,测试通过
图片描述
我们再增加一个方法

public function testMe()
    {
       $this->assertTrue(2 == 2);
    }
    public function testM1()
    {
       $this->assertTrue(2 <1);
    }

图片描述
我们再运行一次
这次提示有testm1是fail,testme 是ok
Tests:2 运行了2个测试方法,
assertions:2运行了2次断言(就是执行了2次名字是assert开头的方法)
Failures: 1有1次断言是失败的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值