Module: TDriverReportTestUnit

Defined in:
lib/tdriver/report/report_test_unit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



116
117
118
119
120
121
# File 'lib/tdriver/report/report_test_unit.rb', line 116

def TDriverReportTestUnit.included(mod)

  create_test_unit_formatter()
  create_global_reporter_hook_for_test_unit()

end

Instance Method Details

#create_test_unit_formatterObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tdriver/report/report_test_unit.rb', line 42

def create_test_unit_formatter()
  eval "
    require 'test/unit'
    require 'test/unit/ui/console/testrunner'
#class for listening test unit execution process
  class TestUnit < Test::Unit::UI::TestRunnerMediator
    include TDriverReportCreator
      def initialize(suite, report_mgr = nil)
        super(suite)
        @tc_result=nil
        @current_suite_name=suite.name
        @current_test_name=nil
        add_listener(Test::Unit::UI::TestRunnerMediator::STARTED, &method(:started))
        add_listener(Test::Unit::TestCase::STARTED, &method(:test_started))
        add_listener(Test::Unit::TestCase::FINISHED, &method(:test_finished))
        add_listener(Test::Unit::TestResult::FAULT, &method(:fault))
      end
      def get_class_name(full_test_name) #:nodoc:
        begin
          name=full_test_name
          name=name.gsub(/[)]/,'')
          name_arr=name.split('(')
          return [name_arr[1].gsub(/[:]/,'_'),name_arr[0].gsub(/[:]/,'_')]
        rescue
          return ['Ruby test',full_test_name]
        end
      end
      #This method initializes new test run
      #
      # === params
      # === returns
      # === raises
      def started(result)
        start_run()
        add_report_group(@current_suite_name+'|')
      end
      #This method starts a new test case
      #
      # === params
      # === returns
      # === raises
      def test_started(name)
        full_name=get_class_name(name)
        @current_test_name=full_name[1]
        add_report_group(@current_suite_name+':'+full_name[0]+'|')
        start_test_case(@current_test_name)
        add_test_case_group(full_name[0])
        @tc_result='passed'
      end
      #This method records the test case result
      #
      # === params
      # === returns
      # === raises
      def test_finished(name)
        if @tc_result=='passed'
          update_test_case('-')
        end
        end_test_case(@current_test_name,@tc_result)
      end
      #This method records the test case fault result
      #
      # === params
      # === returns
      # === raises
      def fault(fault)
        capture_screen_test_case()
        update_test_case(fault)
        @tc_result='failed'
      end
  end
  "
end