如何从 Rails 测试套件运行单个测试? [英] How to run a single test from a rails test suite?
问题描述
如何从 rails 测试套件运行单个测试?
How can I run a single test from a rails test suite?
rake test ANYTHING
似乎没有帮助.
推荐答案
注意: 这不会通过 rake
运行测试.所以你在 Rakefile
中的任何代码都不会被执行.
NOTE: This doesn't run the test via rake
. So any code you have in Rakefile
will NOT get executed.
要运行单个测试,请从 Rails 项目的主目录中使用以下命令:
To run a single test, use the following command from your rails project's main directory:
ruby -I test test/unit/my_model_test.rb -n test_name
这将运行一个名为name"的测试,该测试在指定文件的 MyModelTest 类中定义.test_name 是通过获取测试名称,在它前面加上单词test",然后用下划线分隔单词而形成的.例如:
This runs a single test named "name", defined in the MyModelTest class in the specified file. The test_name is formed by taking the test name, prepending it with the word "test", then separating the words with underscores. For example:
class MyModelTest < ActiveSupport::TestCase
test "valid with good attributes" do
# do whatever you do
end
test "invalid with bad attributes" do
# do whatever you do
end
end
您可以通过以下方式运行这两个测试:
You can run both tests via:
ruby -I test test/unit/my_model_test.rb
以及通过
ruby -I test test/unit/my_model_test.rb -n test_invalid_with_bad_attributes
这篇关于如何从 Rails 测试套件运行单个测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!