Class: Moto::Reporting::TestReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/reporting/test_reporter.rb

Overview

Manages reporting test and run status’ to attached listeners

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listeners, run_params) ⇒ TestReporter

@param run_params Variables specified by the user when parametrizing current moto run

suite_name: String Name of the test suite
run_name:   String Name of the test run, may be custom made or automatically generated
assignee:   ID of person responsible for test run

Parameters:

  • listeners (Array)

    An array of strings, which represent qualified names of classes (listeners) that will be instantiated. empty array is passed then :default_listeners will be taken from config



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/reporting/test_reporter.rb', line 17

def initialize(listeners, run_params)

  if listeners.empty?
    config[:default_listeners].each do |listener_class_name|
      listeners << listener_class_name
    end
  else
    listeners.each_with_index do |listener_class_name, index|
      listeners[index] = ('Moto::Reporting::Listeners::' + listener_class_name.camelize).constantize
    end
  end

  @listeners = []
  @run_params = run_params
  listeners.each { |l| add_listener(l) }
end

Instance Attribute Details

#run_statusObject (readonly)

Returns the value of attribute run_status.



9
10
11
# File 'lib/reporting/test_reporter.rb', line 9

def run_status
  @run_status
end

Instance Method Details

#add_listener(listener) ⇒ Object

Adds a listener to the list. All listeners on the list will have events reported to them.

Parameters:

  • listener (Moto::Listener::Base)

    class to be added



37
38
39
# File 'lib/reporting/test_reporter.rb', line 37

def add_listener(listener)
  @listeners << listener.new(@run_params)
end

#report_end_runObject

Reports end of the whole run (set of tests) to attached listeners



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reporting/test_reporter.rb', line 56

def report_end_run
  @run_status.finalize_run

  @listeners.each do |l|
    begin
      l.end_run(@run_status)
    rescue Exception => e
      puts "Listener #{l.class.name} on End run: #{e.to_s}"
    end
  end
end

#report_end_test(test_status) ⇒ Object

Reports end of a test to all attached listeners

Parameters:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/reporting/test_reporter.rb', line 83

def report_end_test(test_status)
  @run_status.add_test_status(test_status)

  @listeners.each do |l|
    begin
      l.end_test(test_status)
    rescue Exception => e
      puts "Listener #{l.class.name} on End test: #{e.to_s}"
    end
  end
end

#report_start_runObject

Reports start of the whole run (set of tests) to attached listeners



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/reporting/test_reporter.rb', line 42

def report_start_run
  @run_status = Moto::Reporting::RunStatus.new
  @run_status.initialize_run

  @listeners.each do |l|
    begin
      l.start_run
    rescue Exception => e
      puts "Listener #{l.class.name} on Start run: #{e.to_s}"
    end
  end
end

#report_start_test(test_status, test_metadata) ⇒ Object

Reports star of a test to all attached listeners

Parameters:



71
72
73
74
75
76
77
78
79
# File 'lib/reporting/test_reporter.rb', line 71

def report_start_test(test_status, )
  @listeners.each do |l|
    begin
      l.start_test(test_status, )
    rescue Exception => e
      puts "Listener #{l.class.name} on Start test: #{e.to_s}"
    end
  end
end