编程语言
首页 > 编程语言> > php – 如何在Codeception中强制测试失败

php – 如何在Codeception中强制测试失败

作者:互联网

我用Codeception进行WebServices测试,这是我的代码:

//Making first query for getting needed parameter
$I->wantTo('Make something');
$I->sendPOST($this->route, [
    'token' => Fixtures::get('token'),
    'id' => Fixtures::get('some_id')
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('"error_message"');

//Then I get what I need with regexp
if (preg_match('/^.*\s(?<value_i_need>\d+)\.$/', $I->grabDataFromResponseByJsonPath('$.status.error_message')[0], $matches)) {
    $I->sendPOST($this->route, [
        'token' => Fixtures::get('token'),
        'id' => Fixtures::get('some_id')
    ]);
    $I->seeResponseCodeIs(200);
    $I->seeResponseIsJson();
    $I->seeResponseContains('"something"');
    $I->seeResponseContains('"something_else"');   
} else {
    //And if I don't get needed parameter with regular expression, here I have to force test fail
}

有人知道如何强制测试失败吗?

提前致谢!

解决方法:

您可以对actor使用失败操作.即

$I->fail('this test fails... just because');

标签:php,testing,codeception
来源: https://codeday.me/bug/20190528/1169363.html