如何配置rubyunit testing执行?
我想知道运行10个最耗时的测试花了多少…就像我可以用rspec做的,有什么建议吗?
简短回答:
gem install minitest # Install MiniTest gem install minitest_tu_shim # Install Test::Unit shim use_minitest yes # Use MiniTest Test::Unit shim instead of stdlib Test::Unit ruby your_test.rb -v # Run your test in verbose mode
Ruby 1.9使用MiniTest
作为其默认测试框架而不是Test::Unit
。 MiniTest更小,更快,具有更多有用的function,并且与Test :: Unit大部分向后兼容。 其中一个较新的function是使用-v
标志测量每个测试所用的时间。 当你运行时,请确保在脚本之后放置此标志
如果像在rails中一样使用Rake::TestTask
来运行测试,那么你可以在运行时通过运行来指定它
rake test TESTOPTS='-v'
或者通过在options
属性中添加-v
来在任务中指定它,就像这样
Rake::TestTask.new do |t| t.options = '-v' end
最后,如果您正在使用rails并且MiniTest对您来说不够好,您可能会喜欢test_benchmark
插件。 用法很简单。 config/environments/test.rb
下行添加到config/environments/test.rb
config.gem "timocratic-test_benchmark", :lib => 'test_benchmark', :source => 'http://gems.github.com'
安装它
RAILS_ENV='test' rake gems:install
从那时起,当您运行测试时,您将获得一个很好的排序列表
rake test:units [...] Test Benchmark Times: Suite Totals: 7.124 test_destroy(FeedTest) 7.219 test_create(FeedTest) 7.646 test_subscribe_to_auto_discovery(FeedTest) 9.339 test_auto_discover_updates_url(FeedTest) 9.543 test_find_or_create_by_auto_discover_url(FeedTest) 15.780 test_import_from_opml(FeedTest)
我很遗憾地说MiniTest
和test_benchmark
插件彼此不兼容,但我强烈建议您尝试使用MiniTest
,因为它会让您的测试更快,并且将继续在Ruby 1.9中得到支持。
也许通过使用ruby -rprofile
而不仅仅是ruby
执行代码,在ruby profiler下运行unit testing?
Minitest :: Profile是一个新的gem,列出了标准测试运行后的顶级违规者。