我与Mr. Limpens有一个非常相似的问题,其中一个主要不同:我做将test_unit railtie包含到我的application.rb中。
来自我的 application.rb :
require File.expand_path('../boot', __FILE__) # Pick the frameworks you want: require 'action_controller/railtie' require 'dm-rails/railtie' # require 'action_mailer/railtie' # require 'active_resource/railtie' require 'rails/test_unit/railtie' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler)
您会注意到我正在使用DataMapper并使用dm-rails引导程序初始化我的项目。我可以手动运行我的测试,如下所示:
$ ruby -Itest test/unit/test_habit.rb Loaded suite test/unit/test_habit Started ..... Finished in 2.554523 seconds. 5 tests, 7 assertions, 0 failures, 0 errors, 0 skips Test run options: --seed 15947
但是在执行rake测试任务时,没有运行任何测试,如下所示:
$ rake test --trace (in /home/blt/Documents/projects/rails3apps/naughtyapp) ** Invoke test (first_time) ** Execute test ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Execute test:prepare ** Execute test:units ** Invoke test:functionals (first_time) ** Invoke test:prepare ** Execute test:functionals ** Invoke test:integration (first_time) ** Invoke test:prepare ** Execute test:integration
每次运行'first_time'显示在括号中。我的测试没有运行,我必须做错什么?
答案 0 :(得分:11)
我认为rake测试任务正在搜索与test / unit / * * / * _ test.rb等名称匹配的测试文件。因此,您可能只需要将文件名test_habit.rb更改为habit_test.rb。