集成测试未在开发环境中运行

我是ruby on rails的新手,我想写一个简单的测试来检查我的系统的登录function。 我正在关注这个官方文档http://guides.rubyonrails.org/testing.html#integration-testing

我运行命令rails test:integration但是这显示了这个错误

rails aborted! ActiveRecord::EnvironmentMismatchError: You are attempting to modify a database that was last run in `development` environment. You are running in `test` environment. If you are sure you want to continue, first set the environment using: bin/rails db:environment:set RAILS_ENV=test 

为什么我应该切换到测试环境来测试我的应用程序? 如果我切换到测试环境,所有配置都会有所不同。 我们在开发/生产模式下开发然后在测试模式下测试是否奇怪?

这是我的测试数据库

 default: &default adapter: postgresql encoding: unicode host:  username:  password:  pool:  development: <<: *default database: fanshub_development socket:  test: <<: *default database: fanshub_test socket:  production: <<: *default database: fanshub_production  host:   socket:   

如果我切换到测试环境,所有配置都会有所不同。 我们在开发/生产模式下开发然后在测试模式下测试是否奇怪?

不,在专用测试环境中进行测试非常常见。 这使得测试可预测。 您可以使用夹具初始化测试环境。

Rails测试env为每次测试运行重新创建数据库的干净状态。 如果您在开发环境中运行测试,您的开发数据将被删除

确保您使用单独的测试数据库(在database.yml中配置)在测试环境中运行测试