Class: Trainer::XCResult::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
trainer/lib/trainer/xcresult/test_suite.rb

Overview

Represents a test suite, including its test cases and sub-suites

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, identifier:, type:, result:, tags: [], test_cases: [], sub_suites: []) ⇒ TestSuite

Returns a new instance of TestSuite.



15
16
17
18
19
20
21
22
23
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 15

def initialize(name:, identifier:, type:, result:, tags: [], test_cases: [], sub_suites: [])
  @name = name
  @identifier = identifier
  @type = type
  @result = result
  @tags = tags
  @test_cases = test_cases
  @sub_suites = sub_suites
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



8
9
10
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 8

def identifier
  @identifier
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 7

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



10
11
12
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 10

def result
  @result
end

#sub_suitesObject (readonly)

Returns the value of attribute sub_suites.



12
13
14
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 12

def sub_suites
  @sub_suites
end

#tagsObject (readonly)

Returns the value of attribute tags.



13
14
15
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 13

def tags
  @tags
end

#test_casesObject (readonly)

Returns the value of attribute test_cases.



11
12
13
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 11

def test_cases
  @test_cases
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 9

def type
  @type
end

Class Method Details

.from_json(node:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 25

def self.from_json(node:)
  # Create initial TestSuite with basic attributes
  test_suite = new(
    name: node['name'],
    identifier: node['nodeIdentifier'],
    type: node['nodeType'],
    result: node['result'],
    tags: node['tags'] || []
  )

  # Process children to populate test_cases and sub_suites
  test_suite.process_children(node['children'] || [])

  test_suite
end

Instance Method Details

#durationObject



53
54
55
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 53

def duration
  @duration ||= @test_cases.sum(&:duration) + @sub_suites.sum(&:duration)
end

#failed?Boolean

Returns:



45
46
47
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 45

def failed?
  @result == 'Failed'
end

#failures_countObject



61
62
63
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 61

def failures_count
  @failures_count ||= @test_cases.count(&:failed?) + @sub_suites.sum(&:failures_count)
end

#passed?Boolean

Returns:



41
42
43
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 41

def passed?
  @result == 'Passed'
end

#process_children(children) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 121

def process_children(children)
  children.each do |child|
    case child['nodeType']
    when 'Test Case'
      # Use from_json to generate multiple test cases if needed
      @test_cases.concat(TestCase.from_json(node: child))
    when 'Test Suite', 'Unit test bundle', 'UI test bundle'
      @sub_suites << TestSuite.from_json(node: child)
    end
  end
end

#skipped?Boolean

Returns:



49
50
51
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 49

def skipped?
  @result == 'Skipped'
end

#skipped_countObject



65
66
67
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 65

def skipped_count
  @skipped_count ||= @test_cases.count(&:skipped?) + @sub_suites.sum(&:skipped_count)
end

#test_cases_countObject



57
58
59
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 57

def test_cases_count
  @test_cases_count ||= @test_cases.count + @sub_suites.sum(&:test_cases_count)
end

#to_hashObject

Hash representation used by TestParser to collect test results



85
86
87
88
89
90
91
92
93
94
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 85

def to_hash
  {
    number_of_tests: total_tests_count,
    number_of_failures: total_failures_count,
    number_of_tests_excluding_retries: test_cases_count,
    number_of_failures_excluding_retries: failures_count,
    number_of_retries: total_retries_count,
    number_of_skipped: skipped_count
  }
end

#to_xml(output_remove_retry_attempts: false) ⇒ Object

Generates a JUnit-compatible XML representation of the test suite See github.com/testmoapp/junitxml/



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 98

def to_xml(output_remove_retry_attempts: false)
  testsuite = Helper.create_xml_element('testsuite',
    name: @name,
    time: duration.to_s,
    tests: test_cases_count.to_s,
    failures: failures_count.to_s,
    skipped: skipped_count.to_s)

  # Add test cases
  @test_cases.each do |test_case|
    runs = test_case.to_xml_nodes
    runs = runs.last(1) if output_remove_retry_attempts
    runs.each { |node| testsuite.add_element(node) }
  end

  # Add sub-suites
  @sub_suites.each do |sub_suite|
    testsuite.add_element(sub_suite.to_xml(output_remove_retry_attempts: output_remove_retry_attempts))
  end

  testsuite
end

#total_failures_countObject



74
75
76
77
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 74

def total_failures_count
  @test_cases.sum(&:total_failures_count) +
    @sub_suites.sum(&:total_failures_count)
end

#total_retries_countObject



79
80
81
82
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 79

def total_retries_count
  @test_cases.sum(&:retries_count) +
    @sub_suites.sum(&:total_retries_count)
end

#total_tests_countObject



69
70
71
72
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 69

def total_tests_count
  @test_cases.sum(&:total_tests_count) +
    @sub_suites.sum(&:total_tests_count)
end