问题描述
我在某处读到最小"是新的test :: unit for ruby 1.9.2+".
I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+".
但是ruby 1.9.3似乎都包括两者 和 ,是真的吗?
But ruby 1.9.3 seems to include both test::unit and minitest, is that true?
在默认的Rails测试中,如 Rails测试指南 ...中所述,例如ActiveSupport::TestCase
, ActionController::TestCase
,这些是使用Test::Unit
还是Minitest
?
In the default rails testing, as outlined in the Rails testing guide.... things like ActiveSupport::TestCase
, ActionController::TestCase
, are these using Test::Unit
or Minitest
?
在rails指南中,显示了具有如下定义的测试的示例:
In the rails guide, it shows examples with tests defined like this:
test "should show post" do
get :show, :id => @post.id
assert_response :success
end
与 Test::Unit
或Minitest的文档中未提及与定义诸如test_something
之类名称的方法相对的语法test string
.那是哪里来的? Rails是在添加它,还是实际上是...测试lib rails正在使用的一部分?
That syntax, test string
, as opposed to defining methods with names like test_something
-- isn't mentioned in the docs for either Test::Unit
or Minitest. Where's that coming from? Is Rails adding it, or is it actually a part of... whatever testing lib rails is using?
PS:请不要告诉我仅使用rspec".我了解rspec.我正在Rails的背景下尝试探索stdlib的替代方案.
PS: Please don't tell me "just use rspec". I know about rspec. I am trying to explore the stdlib alternatives, in the context of rails.
推荐答案
Minitest附带了一个Test::Unit
"compatibility"模块,因此您可以(大概)按原样使用现有的Test :: Unit测试.这可能是您正在看到的Test::Unit
模块.
There is a Test::Unit
"compatibility" module that comes with Minitest, so that you can (presumably) use your existing Test::Unit tests as-is. This is probably the Test::Unit
module you are seeing.
从rails 3.2.3开始,生成器创建的测试包括rails/test_help
,其中包括test/unit
.
As of rails 3.2.3, generator-created tests include rails/test_help
which includes test/unit
.
test "something" do
语法是Rails扩展.它是在ActiveSupport::Testing::Declarative
中定义的,而ActiveSupport::Testing::Declarative
是rails/test_help
的.
The test "something" do
syntax is a rails extension. It's defined in ActiveSupport::Testing::Declarative
, which is require
'd by rails/test_help
.
这篇关于minitest,test :: unit和rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!