在dev数据库而不是测试数据库上运行的Codeception Acceptance测试

时间:2016-10-27 08:23:47

标签: yii2 codeception

我有一个使用名为前端的数据库的Yii2项目,但我想在名为 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

2 个答案:

答案 0 :(得分:1)

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

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

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

所以在Yii2中寻找配置测试数据库的文件,你准备好了!

答案 1 :(得分:0)

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

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

  

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

相关问题