【问题标题】:What is the proper way to use fixtures with Acceptance tests in Codeception?在 Codeception 中使用带有验收测试的夹具的正确方法是什么?
【发布时间】:2017-10-20 16:07:55
【问题描述】:

我正在使用 Yii2,并希望在我的验收测试中包含固定装置。

通过单元测试,您可以将fixture trait 添加到类中,然后使用fixtures 方法返回一个fixture 数组,然后从_before() 方法调用$this->loadFixtures(),并从_after() 方法调用$this->unloadFixtures()。这非常有效。

在 Cept 验收测试中,不使用类,所以我不知道您将如何在此过程中使用固定装置。

对于 Cest 文件,我尝试将 fixtureTrait 添加到 Cest 类,但没有成功。我什至应该将夹具特征添加到 Cest 文件中吗?

因此,在验收测试中使用夹具的正确方法是什么?

【问题讨论】:

  • 什么?真的是这个问题吗?
  • 我试图改写问题

标签: php yii2 codeception


【解决方案1】:

经过大量的谷歌搜索,我找到了一个令人满意的解决方案。

对于 Cept 文件,由于它们不使用类,因此您必须在 YAML 配置中包含 Yii2 模块,但只有固定装置部分。

在acceptance.suite.yml中:

modules:
    enabled:
        - WebDriver
        - Yii2:
            part:
                - init
                - fixtures
            transaction: false

我使用的是 selenium,所以我也启用了 WebDriver 模块。我还发现有必要设置transaction: false,否则我的登录无效。
(可能是由于 Web 请求无法获得交易数据)

然后我必须运行构建命令以使$I->haveFixtures() 方法可用。

codeception build

我现在可以将夹具作为 Cept 文件的一部分包含在内:

use tests\fixtures\DBAddressFixture;
use tests\fixtures\DBCustomerFixture;
use tests\fixtures\OAuthClientsFixture;

/* @var $scenario Codeception\Scenario */
$I = new AcceptanceTester($scenario);
$I->wantTo("Check that the account information page exists and works");

$I->haveFixtures([
    'customer' => DBCustomerFixture::className(),
    'address' => DBAddressFixture::className(),
    'auth' => OAuthClientsFixture::className()
]);

关于 Cest 文件。显然它应该像将_fixtures() 方法添加到 Cest 类一样简单,尽管我还没有尝试过。

这里有一些有用的链接:

Codeception Yii2 Fixtures Documentation

CodeCeption Fixtures Issue 4099

Similar StackOverflow issue 45881907

Yii2 Fixtures Documentation

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 2016-11-02
    • 2014-02-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多