Class: RubyUnit::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/RubyUnit/Runner.rb

Overview

This is the test runner. Done, and done.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autorun?Boolean

Whether or not the test suite still needs to be run. This is used by the automatic runner to determine if it must be run before the program exits.

RubyUnit::Runner.autorun?

Returns:

  • (Boolean)


69
70
71
# File 'lib/RubyUnit/Runner.rb', line 69

def autorun?
  @@autorun
end

.runObject

The static test runner

  • raises TypeError if any data method doesn’t return an array

  • raises TypeError if any data method doesn’t return an array of arrays

  • Returns the sum of the failure and error counts

RubyUnit::Runner.run


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/RubyUnit/Runner.rb', line 28

def run
  @@autorun = false
  runner    = new
  puts "RubyUnit #{RubyUnit::VERSION}"
  puts "Started Tests #{Report.start.strftime("%Y-%m-%d %H:%M:%S")}"

  TestCase.descendents.each do |test_case|
    @@test_cases << test_case
    object = test_case.new
    test_case.setup

    data_methods = test_case.instance_methods.grep /Data$/
    test_methods = test_case.instance_methods.grep /Test$/

    test_methods.each do |test|
      data_method = "#{test.slice(0..-5)}Data".to_sym
      if data_methods.include? data_method
        data = object.send data_method

        raise TypeError, "Data method #{data_method} must return an array" unless data.is_a? Array
        data.each do |params|
          raise TypeError, "Data method #{data_method} must return an array of arrays" unless data.is_a? Array
          runner.run test_case, test, params
        end
      else
        runner.run test_case, test
      end
    end
    test_case.teardown
  end
  Report.finish
  report unless Report.tests.zero?
  Report.status
end

Instance Method Details

#run(klass, test, params = []) ⇒ Object

Run a test and record the results. The test object is instantiated and TestCaseObject.setup is called. TestCaseObject.teardown is called after the test has finished. This is called by the static runner.

  • raises TypeError unless params is an Array

test_case_class

The test case class that has the test

test

The test that is going to be run

params

The parameters that are passed to test execution

run TestCaseClass, :myTest, [param1, param2]

Raises:

  • (TypeError)


107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/RubyUnit/Runner.rb', line 107

def run klass, test, params = []
  raise TypeError, "Parameter list for #{object.class}::#{test} must be an array" unless params.is_a? Array
  test_case = klass.new

  error = nil
  begin
    test_case.setup
    test_case.send test, *params
    test_case.teardown
  rescue Exception => error
  end
  Result.new test_case.class, test, params, error
end