简体   繁体   English

如何使用 lib minitest 或 Test:Unit 为单元测试着色?

[英]How to color unit tests with lib minitest or Test:Unit?

I would like to have unit tests output color in my dev environment.我想在我的开发环境中对 output 颜色进行单元测试。 However, I can't make it work on Linux (Debian and Ubuntu).但是,我不能让它在 Linux(Debian 和 Ubuntu)上工作。 When I include the following libs:当我包含以下库时:

require 'minitest/autorun'
require 'minitest/unit'
require 'minitest/pride'

I get:我得到:

/usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in `<top (required)>': undefined method `output' for MiniTest::Unit:Class (NoMethodError)

caused by the code:由代码引起:

MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output)

I have seen a working Rspec variant .我见过一个有效的Rspec 变体 Unfortunately, my Ruby knowledge is not enough to see differences.不幸的是,我的 Ruby 知识不足以看出差异。

Give turn a whirl.一转。

Add this to your Gemfile:将此添加到您的 Gemfile 中:

group :test do
  gem 'turn', :require => false
end

step 1: use the latest version of the gem (I think it will be fixed in Ruby 1.9.3)第1步:使用最新版本的gem(我认为它会在Ruby 1.9.3中修复)

gem install minitest

step 2: require "minitest/pride" on the command line, not in your code第 2 步:在命令行上需要“minitest/pride”,而不是在您的代码中

ruby -rminitest/pride your_ruby_script.rb

.. and in your code simply require 'minitest/autorun' ..在你的代码中只需要'minitest/autorun'

require 'minitest/autorun'

If you use Rubymine, just add如果您使用 Rubymine,只需添加

-rminitest

in the default configuration of the tests.在测试的默认配置中。 => the configuration would like => 配置想要

-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -rminitest/pride

simply add these lines to your test_helper.rb file after require 'rails/test_help'只需在 require 'rails/test_help' 之后将这些行添加到您的 test_helper.rb 文件中

require "minitest/reporters"
Minitest::Reporters.use!

in your gemfile add在你的 gemfile 添加

gem 'minitest-reporters', '~> 1.0.7'

this will get your rake test to be in red and green, but it also brings up the backtrace.这将使您的 rake 测试变为红色和绿色,但它也会带来回溯。 to get rid of all those extra backtrace logs add this to your gemfile then bundle:要摆脱所有这些额外的回溯日志,请将其添加到您的 gemfile 然后捆绑:

gem 'mini_backtrace'

then in config/initializers/backtrace_silencers.rb add this line to cut all the extra rvm stuff然后在 config/initializers/backtrace_silencers.rb 添加这一行来削减所有额外的 rvm 东西

Rails.backtrace_cleaner.add_silencer { |line| line =~ /rvm/ }

hope that works for you, let me know if you need more details.希望对您有用,如果您需要更多详细信息,请告诉我。

See https://github.com/tenderlove/purdytest/issues/1 .请参阅https://github.com/tenderlove/purdytest/issues/1 It seems to be a known bug with the minitest version shipped with 1.9.2.这似乎是 1.9.2 附带的 minitest 版本的一个已知错误。 For the others, adding对于其他人,添加

gem "minitest"

at the very top of your file did the trick.在您文件的最顶部就可以了。

I currently use purdytest with 1.9.2我目前使用purdytest和 1.9.2

Try look at this post about using turn gem for nice looking and configurable output for minitest.试试看这篇关于使用 turn gem 获得漂亮外观和可配置 output 进行 minitest 的帖子。 http://rawonrails.blogspot.com/2012/01/better-minitest-output-with-turn-gem.html http://rawonrails.blogspot.com/2012/01/better-minitest-output-with-turn-gem.html

$ gem install mynyml-redgreen --source http://gemcutter.org

# in your test file
require 'redgreen'

redgreen and turn work nicely in conjunction with each other, by the way顺便说一下,redgreen 和 turn 可以很好地协同工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM