【问题标题】:Codeception Acceptance test running on the dev database instead of the test database在开发数据库而不是测试数据库上运行的 Codeception 验收测试
【发布时间】:2016-10-27 08:23:46
【问题描述】:

我有一个 Yii2 项目,它使用一个名为 frontend 的数据库,但我想在另一个名为 codeception 的数据库上运行我的验收测试。问题是当我运行测试时,它仍然使用 frontend 数据库而不是 codeception 数据库。是不是可以在不同的数据库上运行验收测试,还是我做错了什么?

acceptance.suite.yml

class_name: AcceptanceTester
modules:
  enabled: [ WebDriver, Db ]

  config:
    Db:
        dsn: 'mysql:host=localhost;dbname=codeception'
        user: 'root'
        password: ''
        dump: _data/dump.sql
        populate: true
        cleanup: false
    WebDriver:
        url: 'http://localhost:8080/myproject/frontend/web'
        browser: 'firefox'

env:
  chrome:
        modules:
                config:
                        WebDriver:
                                  browser: 'chrome'

前端\codeception.yml

namespace: tests\codeception\frontend
actor: Tester
paths:
  tests: .
  log: _output
  data: _data
  helpers: _support
settings:
  bootstrap: _bootstrap.php
  suite_class: \PHPUnit_Framework_TestSuite
  colors: true
  memory_limit: 1024M
  log: true
config:
  test_entry_url: http://localhost:8080/myproject/web/index-test.php

【问题讨论】:

    标签: yii2 codeception


    【解决方案1】:

    当然,您可以针对测试数据库运行验收测试!

    但是,您必须将网站配置为在不同 url 上运行时使用测试数据库,并让 Codeception 针对测试 url 运行测试。我用 Yii1 和一些自定义框架做到了这一点。

    我看到您已经在针对 index-test.php 运行 codeception。在 Yii1 中,有一个 test.php 配置文件,您可以在其中设置测试数据库的连接,我假设 Yii2 以类似的方式工作。

    所以在 Yii2 中寻找配置测试数据库的文件,就可以开始了!

    【讨论】:

      【解决方案2】:

      如果您使用的是 PhpBrowser 或 WebDriver 模块,它们会通过 HTTP 向被测网站发出请求,而 Codeception 无法控制网站的配置和执行。

      只有功能测试(例如使用Yii2 module)才能更改应用程序的配置。

      configFile required - 应用程序配置文件的路径。测试环境配置文件并返回配置数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-08
        • 1970-01-01
        相关资源
        最近更新 更多