Class: Trainer::XCResult::TestCase
- Inherits:
-
Object
- Object
- Trainer::XCResult::TestCase
- Includes:
- TestCaseAttributes
- Defined in:
- trainer/lib/trainer/xcresult/test_case.rb
Overview
Represents a test case, including its retries (aka repetitions)
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#classname ⇒ Object
readonly
Returns the value of attribute classname.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#failure_messages ⇒ Object
readonly
Returns the value of attribute failure_messages.
-
#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.
-
#retries ⇒ Array<Repetition>
readonly
This will be ‘nil` if the test case was not run multiple times, but will contain all repetitions if it was run more than once.
-
#source_references ⇒ Object
readonly
Returns the value of attribute source_references.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, identifier:, duration:, result:, classname:, argument: nil, tags: [], retries: nil, failure_messages: [], source_references: [], attachments: []) ⇒ TestCase
constructor
A new instance of TestCase.
- #retries_count ⇒ Object
-
#to_xml_nodes ⇒ Array<REXML::Element>
Generates XML nodes for the test case.
- #total_failures_count ⇒ Object
- #total_tests_count ⇒ Object
Methods included from TestCaseAttributes
#failed?, included, #passed?, #skipped?
Constructor Details
#initialize(name:, identifier:, duration:, result:, classname:, argument: nil, tags: [], retries: nil, failure_messages: [], source_references: [], attachments: []) ⇒ TestCase
Returns a new instance of TestCase.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 25 def initialize( name:, identifier:, duration:, result:, classname:, argument: nil, tags: [], retries: nil, failure_messages: [], source_references: [], attachments: [] ) @name = name @identifier = identifier @duration = duration @result = result @classname = classname @argument = argument = @retries = retries = @source_references = source_references = end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
16 17 18 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 16 def argument @argument end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
22 23 24 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 22 def end |
#classname ⇒ Object (readonly)
Returns the value of attribute classname.
15 16 17 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 15 def classname @classname end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
13 14 15 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 13 def duration @duration end |
#failure_messages ⇒ Object (readonly)
Returns the value of attribute failure_messages.
20 21 22 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 20 def end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
12 13 14 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 12 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 11 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
14 15 16 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 14 def result @result end |
#retries ⇒ Array<Repetition> (readonly)
This will be ‘nil` if the test case was not run multiple times, but will contain all repetitions if it was run more than once.
19 20 21 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 19 def retries @retries end |
#source_references ⇒ Object (readonly)
Returns the value of attribute source_references.
21 22 23 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 21 def source_references @source_references end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
23 24 25 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 23 def end |
Class Method Details
.from_json(node:) ⇒ Object
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 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 42 def self.from_json(node:) # Handle test case arguments argument_nodes = Helper.find_json_children(node, 'Arguments') argument_nodes = [nil] if argument_nodes.empty? # Generate test cases for each argument argument_nodes.map do |arg_node| # For repetition nodes, failure messages, source refs, attachments and result attributes, # Search them as children of the argument child node if present, of the test case node otherwise. node_for_attributes = arg_node || node retries = Helper.find_json_children(node_for_attributes, 'Repetition', 'Test Case Run') &.map { |rep_node| Repetition.from_json(node: rep_node) } || [] = if retries.empty? (node_for_attributes) else retries.flat_map(&:failure_messages) end source_references = if retries.empty? extract_source_references(node_for_attributes) else retries.flat_map(&:source_references) end = if retries.empty? (node_for_attributes) else retries.flat_map(&:attachments) end new( name: node['name'], identifier: node['nodeIdentifier'], duration: parse_duration(node['duration']), result: node_for_attributes['result'], classname: extract_classname(node), argument: arg_node&.[]('name'), # Only set if there is an argument tags: node['tags'] || [], retries: retries, failure_messages: , source_references: source_references, attachments: ) end end |
Instance Method Details
#retries_count ⇒ Object
114 115 116 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 114 def retries_count @retries&.count || 0 end |
#to_xml_nodes ⇒ Array<REXML::Element>
Generates XML nodes for the test case
-
If no retries, the array contains a single <testcase> element
-
If retries, the array contains one <testcase> element per retry
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 96 def to_xml_nodes runs = @retries.nil? || @retries.empty? ? [nil] : @retries runs.map do |run| Helper.create_xml_element('testcase', name: if @argument.nil? @name else @name.match?(/(\(.*\))/) ? @name.gsub(/(\(.*\))/, "(#{@argument})") : "#{@name} (#{@argument})" end, classname: @classname, time: (run || self).duration.to_s).tap do |testcase| add_xml_result_elements(testcase, run || self) add_properties_to_xml(testcase, repetition_name: run&.name) end end end |
#total_failures_count ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 122 def total_failures_count if retries_count > 0 @retries.count(&:failed?) elsif failed? 1 else 0 end end |
#total_tests_count ⇒ Object
118 119 120 |
# File 'trainer/lib/trainer/xcresult/test_case.rb', line 118 def total_tests_count retries_count > 0 ? retries_count : 1 end |