##Gemfile加入相关测试驱动:
123456789101112131415161718 #测试组group :test dogem "minitest"gem 'minitest-spec-rails'gem 'minitest-reporters'gem 'spring'gem 'guard'gem 'guard-minitest'# 添加调用跟踪静默程序# gem 'mini_backtrace'gem 'ruby-prof'gem 'minitest-rails-capybara'gem 'autotest-standalone' # The file '.autotest' makes sure the tests are run via test server (spork).gem 'autotest-rails-pure' # -pure gives us autotest without ZenTest gem.gem 'autotest-growl' # growl notifications, complains a little bit if growl isn't installedgem 'autotest-fsevent' # react to filesystem events, save your CPUgem 'spork-minitest'end
##初始化guard:
guard init minitest
##配置guard:
##运行Guard:
输入
guard
命令运行测试
##例外
如果database不用默认的数据库迁移,测试时可以在db下放入
structure.sql
, 该配置为数据库结构,然后更改配置文件application.rb
:
1 config.active_record.schema_format = :sql
运行:rake db:test:prepare
##生成集成化测试文件
rails g test_unit:integration testName
##生成model测试文件
rails g test_unit:model