如何从 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 测试套件运行单个测试?
发布评论