【问题标题】:Yii2 acceptance tests. Rollback all changes that were made in acceptance test after each testYii2 验收测试。在每次测试后回滚在验收测试中所做的所有更改
【发布时间】:2018-12-12 16:00:22
【问题描述】:

我需要在每次验收测试后恢复通过验收测试在数据库中所做的所有更改。

如 Yii2 文档中所述,您应该在 acceptance.suite.yml 中为 Yii2 模块设置 transaction: false。 你应该在codeception.yml 中将cleanup: true and transaction: true 用于Db 模块。

实际:验收测试在数据库中所做的更改还原。

预期:验收测试在数据库中所做的更改被还原。

codeception.yml

namespace: common\tests
actor_suffix: Tester
paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Yii2:
            configFile: 'config/test-local.php'
        Db:
            dsn: '%TEST_DB_TYPE%:host=%TEST_DB_HOST%;port=%TEST_DB_PORT%;dbname=%TEST_DB_NAME%'
            user: '%TEST_DB_USERNAME%'
            password: '%TEST_DB_PASSWORD%'
            cleanup: true
            transaction: true
params:
    - config/params-local.php

acceptance.suite.yml

suite_namespace: frontend\tests\acceptance
actor: AcceptanceTester
modules:
  enabled:
    - WebDriver
    - Yii2
  config:
    Yii2:
      part: init
      transaction: false
      cleanup: true
    WebDriver:
      browser: chrome
      url: 'http://mysite.dev/'
      port: 9515 # ChromeDriver port
      window_size: 1920x1080
      clear_cookies: true
      restart: true
      capabilities:
        chromeOptions:
          args: ["--headless", "--disable-gpu"]
          binary: "/usr/bin/google-chrome-stable"

extensions:
  enabled:
  - Codeception\Extension\RunProcess:
    - chromedriver --url-base=/wd/hub

【问题讨论】:

    标签: yii2 codeception acceptance-testing


    【解决方案1】:

    Yii2 模块对验收测试中应用程序代码的执行没有影响。

    不可能知道您的应用程序对数据库进行了哪些更改,因此您唯一的选择是从备份中恢复数据库。

    为了在测试之前使数据库处于已知状态,您可以使用DB moduledump 选项加载 SQL 文件,但不要对生产数据库执行此操作。

    【讨论】:

    • 所以事务:真实(不使用转储)对于 Db 模块也不起作用? as transaction: true 应该将在测试中进行的所有查询包装到事务中,并在测试结束时回滚事务。这适用于单元和功能测试,但不适用于验收..
    • 它不会包装应用程序代码所做的查询,因为您的应用程序正在使用不同的数据库连接。
    猜你喜欢
    • 2011-12-02
    • 2011-04-12
    • 2014-02-01
    • 2023-04-09
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    相关资源
    最近更新 更多