Class: CTT::Cli::TestReport

Inherits:
Object show all
Defined in:
lib/cli/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_file) ⇒ TestReport

Returns a new instance of TestReport.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cli/report.rb', line 7

def initialize(xml_file)
  unless File.exists?(xml_file)
    say("Test result file: #{xml_file} does not exist. abort!", :red)
    exit(1)
  end

  begin
    @doc = LibXML::XML::Document.file(xml_file)
  rescue Exception => e
    say("Test result file: #{xml_file} is not a valid xml document. abort!", :red)
    exit(1)
  end
end

Instance Attribute Details

#summaryObject (readonly)

Returns the value of attribute summary.



5
6
7
# File 'lib/cli/report.rb', line 5

def summary
  @summary
end

Instance Method Details

#get_durationObject



38
39
40
41
42
# File 'lib/cli/report.rb', line 38

def get_duration
  # duration
  duration = @doc.find_first("/result/duration")
  @summary[:duration] += duration.content.to_f
end

#get_failed_case(case_node) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/cli/report.rb', line 44

def get_failed_case(case_node)
  # failed
  failed = case_node.find_first("errorDetails")
  if failed
    @summary[:failed] += 1
    @summary[:failed_cases] << case_node.find_first("rerunCommand").content
  end
end

#get_pending_case(case_node) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/cli/report.rb', line 53

def get_pending_case(case_node)
  # pending
  pending = case_node.find_first("skipped")
  if pending.content == "true"
    @summary[:pending] += 1
    @summary[:pending_cases] << case_node.find_first("testName").content
  end
end

#parseObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cli/report.rb', line 21

def parse
  @summary = {:total => 0,
              :failed => 0,
              :pending => 0,
              :duration => 0.0,
              :failed_cases => [],
              :pending_cases => []}

  cases = @doc.find("//case")
  @summary[:total] = cases.size
  get_duration
  cases.each do |c|
    get_failed_case(c)
    get_pending_case(c)
  end
end