用cppunit给每个函数添加运行时间统计

Badia ·
更新时间:2024-09-21
· 898 次阅读

必须是ruby1.8.x的版本,我用的是1.8.6,因为1.9的版本里边没有这个文件,文件路径为到ruby的安装目录下的/test/unit/testcase.rb路径下 def run(result)         yield(STARTED, name)         @_result = result         begin           setup              puts "Test method:#{self}"              num="#{self}".scan(/d{1}/)[1]               puts "this is the #{num} testcase"              #puts "this is the d{1,} testcase"           time=Time.now           __send__(@method_name)                       difference = Time.now - time     seconds    =  difference % 60     #sec=seconds.to_s.scan(/d*/)[0]     sec=seconds.round     difference = (difference - seconds) / 60     minutes    =  (difference % 60).round     difference = (difference - minutes) / 60     hours      =  (difference % 24).round

    puts "Runtime is: #{hours} hours #{minutes} minutes #{sec} seconds"         rescue AssertionFailedError => e           add_failure(e.message, e.backtrace)         rescue StandardError, ScriptError           add_error($!)         ensure           begin             teardown           rescue AssertionFailedError => e             add_failure(e.message, e.backtrace)           rescue StandardError, ScriptError             add_error($!)           end         end         result.add_run         yield(FINISHED, name)       end



cppunit 运行 函数

需要 登录 后方可回复, 如果你还没有账号请 注册新账号