仍然可以在导轨4中使用测试单元吗? [英] Is it still possible to use test-unit in rails 4?
问题描述
从Rails 3.2升级到Rails 4后,我的应用程序可以工作了,但是我用测试单元编写的测试是一场灾难.
After upgrading from Rails 3.2 to Rails 4, my app works, but my tests, written with test-unit, are a disaster.
有传言称Minitest与测试单元兼容".但是,如果我尝试使用(现在捆绑在一起的)Minitest,则存在许多差异-从assert *语句名称和参数到(显然)许多其他东西,无论大小,都微妙.
Minitest is rumored to be "compatible" with test-unit. However, if I attempt to use the (now bundled) Minitest, there are a raft of differences - from the assert* statement names and parameters to (clearly) many other things things both large and subtle.
如果我改为避免使用Minitest并尝试将测试单元gem保留在我的Gemfile中,则rake test会爆炸,说:
If I instead try to avoid Minitest and attempt to keep my test-unit gem in my Gemfile, rake test explodes, saying,
undefined method 'refute_predicate' for class 'ActiveSupport::TestCase'
这是由于打电话给
require 'rails/test_help'
:(
我已经搜索了一段时间,但还没有找到继续使用测试单元的任何方法.唯一的选择似乎是(对于我们而言,是大量的)重构测试代码,因为大约80%的测试由于Minitest与测试单元的不兼容而以某种或其他方式破坏了.
I have been searching for a while but have not yet figured out any way to continue using test-unit. The only alternative would seem to be a (for us, massive) refactoring of our test code, since something like 80% of our tests are broken in some way or other by Minitest's incompatibilities with test-unit.
还需要阅读,例如 http://weblog.rubyonrails. org/2013/6/25/Rails-4-0-final/和
Yet reading i.e. http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/ and http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0 I find no mention of this in substance - I feel like must be missing something.
是否可以通过系统的方式使Minitest与测试单元更加兼容?还是要继续在Rails 4中使用测试单元?
Is it possible to make Minitest more compatible with test-unit in a systematic way? Or to continue using test-unit in Rails 4?
推荐答案
您是否在继承:Test :: Unit :: TestCase而不是ActiveSupport :: TestCase?
Are you subclassing: Test::Unit::TestCase and not ActiveSupport::TestCase?
也许尝试将minitest_tu_shim添加到您的测试组:
Maybe try adding minitest_tu_shim to your test group:
https://github.com/seattlerb/minitest_tu_shim
或确保子类ActiveSupport :: TestCase
or make sure to subclass ActiveSupport::TestCase
这篇关于仍然可以在导轨4中使用测试单元吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!