Class: Trainer::XCResult::TestSuite
- Inherits:
-
Object
- Object
- Trainer::XCResult::TestSuite
- 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
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#sub_suites ⇒ Object
readonly
Returns the value of attribute sub_suites.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#test_cases ⇒ Object
readonly
Returns the value of attribute test_cases.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
- #failed? ⇒ Boolean
- #failures_count ⇒ Object
-
#initialize(name:, identifier:, type:, result:, tags: [], test_cases: [], sub_suites: []) ⇒ TestSuite
constructor
A new instance of TestSuite.
- #passed? ⇒ Boolean
- #process_children(children) ⇒ Object
- #skipped? ⇒ Boolean
- #skipped_count ⇒ Object
- #test_cases_count ⇒ Object
-
#to_hash ⇒ Object
Hash representation used by TestParser to collect test results.
-
#to_xml(output_remove_retry_attempts: false) ⇒ Object
Generates a JUnit-compatible XML representation of the test suite See github.com/testmoapp/junitxml/.
- #total_failures_count ⇒ Object
- #total_retries_count ⇒ Object
- #total_tests_count ⇒ Object
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 = @test_cases = test_cases @sub_suites = sub_suites end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
8 9 10 |
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 8 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 7 def name @name end |
#result ⇒ Object (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_suites ⇒ Object (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 |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
13 14 15 |
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 13 def end |
#test_cases ⇒ Object (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 |
#type ⇒ Object (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
#duration ⇒ Object
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
45 46 47 |
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 45 def failed? @result == 'Failed' end |
#failures_count ⇒ Object
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
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
49 50 51 |
# File 'trainer/lib/trainer/xcresult/test_suite.rb', line 49 def skipped? @result == 'Skipped' end |
#skipped_count ⇒ Object
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_count ⇒ Object
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_hash ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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_count ⇒ Object
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 |