我正试图将性能测试整合到一个非Rails应用程序的测试套件中,并遇到了一些问题。
config.filter_run_excluding :perf => true似乎是个坏主意。发布于 2019-04-21 19:01:48
我创建了rspec-基准 Ruby,用于在RSpec中编写性能测试。它对测试速度、资源使用和可伸缩性有很多期望。
例如,要测试代码的速度:
expect { ... }.to perform_under(60).ms或者与另一个实现进行比较:
expect { ... }.to perform_faster_than { ... }.at_least(5).times或者测试计算复杂性:
expect { ... }.to perform_logarithmic.in_range(8, 100_000)或者查看分配了多少个对象:
expect {
_a = [Object.new]
_b = {Object.new => 'foo'}
}.to perform_allocation({Array => 1, Object => 2}).objects要筛选测试,可以将规范分离到performance目录中,并添加rake任务。
require 'rspec/core/rake_task'
desc 'Run performance specs'
RSpec::Core::RakeTask.new(:perf) do |task|
task.pattern = 'spec/performance{,/*/**}/*_spec.rb'
end然后在需要的时候运行它们:
rake perf发布于 2012-06-24 21:58:43
第一个问题部分解决,第二个问题在spec/spec_helper.rb中用这段代码完全解决。
class MessageHelper
class << self
def messages
@messages ||= []
end
def add(msg)
messages << msg
end
end
end
def message(msg)
MessageHelper.add msg
end
RSpec.configure do |c|
c.filter_run_excluding :perf => !ENV["PERF"]
c.after(:suite) do
puts "\nMessages:"
MessageHelper.messages.each {|m| puts m}
end
endhttps://stackoverflow.com/questions/11178530
复制相似问题