如何从 Rails 测试套件运行单个测试?

编程入门 行业动态 更新时间:2024-10-18 08:32:04
本文介绍了如何从 Rails 测试套件运行单个测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

本文发布于:2023-11-07 10:50:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   套件   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!