Class: Turn::TestRunner
- Inherits:
-
Test::Unit::UI::Console::TestRunner
- Object
- Test::Unit::UI::Console::TestRunner
- Turn::TestRunner
- Defined in:
- lib/turn/runners/testrunner.rb
Overview
TestUnit TestRunner
– TODO: Add minitest runner. ++
Instance Method Summary collapse
- #attach_to_mediator ⇒ Object
-
#initialize(controller) ⇒ TestRunner
constructor
A new instance of TestRunner.
-
#setup_mediator ⇒ Object
This is copied verbatim from test/unit/ui/console/testrunner.rb.
-
#t_attach_to_mediator ⇒ Object
Is this needed?.
- #t_case_finished(name) ⇒ Object
- #t_case_started(name) ⇒ Object
- #t_fault(fault) ⇒ Object
- #t_finished(elapsed_time) ⇒ Object
- #t_started(result) ⇒ Object
- #t_test_finished(name) ⇒ Object
- #t_test_started(name) ⇒ Object
Constructor Details
#initialize(controller) ⇒ TestRunner
Returns a new instance of TestRunner.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/turn/runners/testrunner.rb', line 20 def initialize(controller) output_level = 2 # 2-NORMAL 3-VERBOSE controller.loadpath.each{ |path| $: << path } unless controller.live? controller.requires.each{ |path| require(path) } [controller.files].flatten.each{ |path| require(path) } sub_suites = [] ObjectSpace.each_object(Class) do |klass| if(Test::Unit::TestCase > klass) sub_suites << klass.suite end end suite = Test::Unit::TestSuite.new('') # FIXME: Name? sub_suites.sort_by{|s|s.name}.each{|s| suite << s} @t_reporter = controller.reporter super(suite, output_level, $stdout) end |
Instance Method Details
#attach_to_mediator ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/turn/runners/testrunner.rb', line 45 def attach_to_mediator @mediator.add_listener(::Test::Unit::UI::TestRunnerMediator::STARTED, &method(:t_started)) @mediator.add_listener(::Test::Unit::UI::TestRunnerMediator::FINISHED, &method(:t_finished)) @mediator.add_listener(::Test::Unit::TestSuite::STARTED, &method(:t_case_started)) @mediator.add_listener(::Test::Unit::TestSuite::FINISHED, &method(:t_case_finished)) @mediator.add_listener(::Test::Unit::TestCase::STARTED, &method(:t_test_started)) @mediator.add_listener(::Test::Unit::TestCase::FINISHED, &method(:t_test_finished)) @mediator.add_listener(::Test::Unit::TestResult::FAULT, &method(:t_fault)) @io.sync = true @t_result = nil @t_fault = nil @t_previous_run_count = 0 @t_previous_error_count = 0 @t_previous_failure_count = 0 @t_previous_assertion_count = 0 end |
#setup_mediator ⇒ Object
This is copied verbatim from test/unit/ui/console/testrunner.rb. It is here for one simple reason: to supress testunits output of “Loaded Suite”.
142 143 144 145 146 147 148 149 |
# File 'lib/turn/runners/testrunner.rb', line 142 def setup_mediator @mediator = create_mediator(@suite) suite_name = @suite.to_s if ( @suite.kind_of?(Module) ) suite_name = @suite.name end #output("Loaded suite #{suite_name}") end |
#t_attach_to_mediator ⇒ Object
Is this needed?
43 |
# File 'lib/turn/runners/testrunner.rb', line 43 alias :t_attach_to_mediator :attach_to_mediator |
#t_case_finished(name) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/turn/runners/testrunner.rb', line 108 def t_case_finished(name) # Err.. why is testunit running this on the suite? return if name=='' # FIXME skip suite call #t = @t_result.run_count - @t_previous_run_count #f = @t_result.failure_count - @t_previous_failure_count #e = @t_result.error_count - @t_previous_error_count a = @t_result.assertion_count - @t_previous_assertion_count #@t_case.counts(t,a,f,e) @t_case.count_assertions = a #@t_previous_run_count = @t_result.run_count.to_i #@t_previous_failure_count = @t_result.failure_count.to_i #@t_previous_error_count = @t_result.error_count.to_i @t_previous_assertion_count = @t_result.assertion_count.to_i @t_reporter.finish_case(@t_case) end |
#t_case_started(name) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/turn/runners/testrunner.rb', line 72 def t_case_started(name) # Err.. why is testunit running this on the suite? (@not_first_case = true; return) unless @not_first_case @t_case = @t_suite.new_case(name) @t_reporter.start_case(@t_case) end |
#t_fault(fault) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/turn/runners/testrunner.rb', line 87 def t_fault(fault) case fault when ::Test::Unit::Error msg = "" msg << fault.to_s.split("\n")[2..-1].join("\n") @t_test.error!(msg) @t_reporter.error(msg) when ::Test::Unit::Failure msg = "" msg << fault.location[0] << "\n" msg << fault. #.gsub("\n","\n") @t_test.fail!(msg) @t_reporter.fail(msg) end end |
#t_finished(elapsed_time) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/turn/runners/testrunner.rb', line 129 def t_finished(elapsed_time) #@t_suite.count_tests = @t_result.run_count #@t_suite.count_failures = @t_result.failure_count #@t_suite.count_errors = @t_result.error_count #@t_suite.count_passes = @t_result.run_count - @t_result.failure_count - @t_result.error_count @t_suite.count_assertions = @t_result.assertion_count @t_reporter.finish_suite(@t_suite) end |
#t_started(result) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/turn/runners/testrunner.rb', line 65 def t_started(result) @t_suite = Turn::TestSuite.new #@suite @t_suite.size = @suite.size @t_result = result @t_reporter.start_suite(@t_suite) end |
#t_test_finished(name) ⇒ Object
103 104 105 106 |
# File 'lib/turn/runners/testrunner.rb', line 103 def t_test_finished(name) @t_reporter.pass if @t_test.pass? @t_reporter.finish_test(@t_test) end |
#t_test_started(name) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/turn/runners/testrunner.rb', line 79 def t_test_started(name) methname, tcase = name.scan(%r/^([^\(]+)\(([^\)]+)\)/o).flatten! @t_test = @t_case.new_test(methname) #@t_test.file = tcase #@t_test.name = method @t_reporter.start_test(@t_test) end |