建立测试数据

为了进行测试,我们希望确保测试数据库具有与开发数据库相同的表结构。我们不必管理那些装载数据库模式的 DDL 脚本,而是使用 Rake 命令帮助创建测试环境。运行 rake --tasks 命令,就会显示几个用来构建或清空测试数据库的命令:

清单 3. Rake --tasks 输出
rake db:test:clone             # Recreate the test database from the current 
                               # environment's  database schema
rake db:test:clone_structure   # Recreate the test databases from the development 
                               # structure
rake db:test:prepare           # Prepare the test database and load the schema                                 rake test:prepare (rails4)
rake db:test:purge             # Empty the test database
用 rake db:test:prepare 命令在数据库中建立表。这个命令会将开发数据库中的数据库模式复制到测试数据库中。
posted on 2014-04-03 15:59  qinyan20  阅读(170)  评论(0编辑  收藏  举报