gpt4 book ai didi

php - Codeception - 依赖父类中的测试

转载 作者:行者123 更新时间:2023-11-28 20:14:33 27 4
gpt4 key购买 nike

是否有可能拥有扩展父类的 Cest 文件并使用其他测试依赖于使用 @depends 的公共(public)测试“登录”

所以我的 Cest 文件看起来与这篇文章中找到的文件相似,它解释了如何在另一个测试中登录和重新使用 cookie - https://stackoverflow.com/a/25547268/682754

我有这个公共(public)类,但子类中的测试没有运行并输出...此测试取决于“commonCest::login”是否通过。

<?php

class commonCest {

const COOKIE_NAME = 'PHPSESSID';

protected $cookie;

/**
* Most tests will need to depend on this function as it logs the user in and stores the session cookie, use the
* "@depends" phpdoc comment
*
* The cookie in then re-used by calling the following in tests:
*
* $I->setCookie(self::COOKIE_NAME, $this->cookie);
*
* @param \AcceptanceTester $I
*/
public function login(AcceptanceTester $I) {
$I->wantTo('Login');
$I->amOnPage('/login');
$I->fillField(array('name' => 'username'), 'aaaaaa');
$I->fillField(array('name' => 'password'), 'abcdef');
$I->click('.form-actions button');
$I->seeElement('.username');
$this->cookie = $I->grabCookie(self::COOKIE_NAME);
}
}

<?php
use \AcceptanceTester;

class rolesCest extends commonCest
{

/**
* @depends login (This doesn't work)
* @depends commonCest:login (This doesn't work)
* @depends commonCest::login (This doesn't work)
*/
public function listUsers(AcceptanceTester $I)
{
// tests
}

?>

最佳答案

在您的 cest 目录下不要有 commonCest。然后,将针对 cest 目录中扩展 commonCest 的类的每个案例运行登录,因为它存在于所有这些目录中。但是,您不应该为此使用@depends。相反,登录应该在您的 Actor 或助手中,并且应该在您的父类中从 _before 中调用。

或者只使用 stepobjects https://codeception.com/docs/06-ReusingTestCode#stepobjects并从 _before

调用你需要的函数

关于php - Codeception - 依赖父类中的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33259360/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com