trainer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9bd919dd0dc94df63dac316b75515bd599fa555
4
- data.tar.gz: c7899ff83d99d07ed2c4a9afc10a1c1656dab42e
3
+ metadata.gz: e4fdc3ecab3134a832020e1df9dd3ec99d8051e1
4
+ data.tar.gz: 54bc13c8d9eeec5cae850bb244a524c73e73e748
5
5
  SHA512:
6
- metadata.gz: cfcc1720af088d7285b8d8f53e323fb451148f814cd0df1c4acff9bf4ab0d5f84a757ad8c9902796f3c21e5e6e20875a958d4f0d96bf0b603e95e3a3bc8bb9c9
7
- data.tar.gz: e00913b6fa064c578feb850816736498983970cddb406ff24c3a44e524fec737280d89e82c625f743e0635d2931ed38cdab7955c2c094f76d870ba8a897183e3
6
+ metadata.gz: aaa4065186e3ab94e98e17cc86ed25a2776ec4bbec4fc7405ef972e5125840c425f5a579c85200711bfb4e7c54ba1023c19669329a912da61d27913d7f5aa084
7
+ data.tar.gz: 9ea447a20ece504c7328719411ab0430de8c1a5f73ddc19a0ecc31c8868be3918a4fcf9d4300447add7d4495c624f55951aa732f8555946cde93132f9d48ba55
data/README.md CHANGED
@@ -18,11 +18,13 @@ Prettify the `xcodebuild` output | :white_check_mark: | :no_entry_sign:
18
18
  Generate JUnit reports | :white_check_mark: | :white_check_mark:
19
19
  Generate HTML reports | :white_check_mark: | :no_entry_sign:
20
20
  Works when the `xcodebuild` output format changed | :no_entry_sign: | :white_check_mark:
21
- Show test execution duration | :white_check_mark: | :no_entry_sign:
21
+ Show test execution duration | :white_check_mark: | :white_check_mark:
22
22
  Speed | :car: | :rocket:
23
23
 
24
24
  [xcpretty](https://github.com/supermarin/xcpretty) is a great piece of software that is used across all [fastlane tools](https://fastlane.tools). `trainer` was built to have the minimum code to generate JUnit reports for your CI system.
25
25
 
26
+ More information about the why `trainer` is useful can be found on [my blog](https://krausefx.com/blog/trainer-the-simplest-way-to-generate-a-junit-report-of-your-ios-tests).
27
+
26
28
  ## Use with [fastlane](https://fastlane.tools)
27
29
 
28
30
  Update to the latest [fastlane](https://fastlane.tools) and run
@@ -35,23 +37,20 @@ Now add the following to your `Fastfile`
35
37
 
36
38
  ```ruby
37
39
  lane :test do
38
- begin
39
- scan(workspace: "Themoji.xcworkspace", scheme: "ThemojiUITests", output_types: "")
40
- rescue => ex
41
- failure = ex
42
- end
43
-
44
- trainer(output_directory: "/tmp/fastlane_trainer/#{Time.now.to_i}")
45
- raise failure if failure
40
+ scan(scheme: "ThemojiUITests",
41
+ output_types: "",
42
+ fail_build: false)
43
+
44
+ trainer(output_directory: ".")
46
45
  end
47
46
  ```
48
47
 
49
- This will generate the JUnit file in the temporary location `/tmp/fastlane_trainer/[time]`. You can specify any path you want, just make sure to have it clean for every run so that your CI system knows which one to pick.
48
+ This will generate the JUnit file in the current directory. You can specify any path you want, just make sure to have it clean for every run so that your CI system knows which one to pick.
50
49
 
51
50
  If you use circle, use the following to automatically publish the JUnit reports
52
51
 
53
52
  ```ruby
54
- trainer(output_directory: (ENV["CIRCLE_TEST_REPORTS"] || "/tmp"))
53
+ trainer(output_directory: ENV["CIRCLE_TEST_REPORTS"])
55
54
  ```
56
55
 
57
56
  For more information, check out the [fastlane plugin docs](fastlane-plugin-trainer#readme).
@@ -102,7 +101,7 @@ trainer --help
102
101
 
103
102
  ### Show the test results right in your pull request
104
103
 
105
- To make it easier for you and your contributors to see the test failures, you should start using [danger](http://danger.systems) with the [danger-junit](https://github.com/orta/danger-junit) plugin
104
+ To make it easier for you and your contributors to see the test failures, you can use [danger](http://danger.systems) with the [danger-junit](https://github.com/orta/danger-junit) plugin to automatically post the test failures on the GitHub PR.
106
105
 
107
106
  ![](assets/danger-output.png)
108
107
 
@@ -6,9 +6,9 @@
6
6
 
7
7
  <testsuites tests="<%= number_of_tests %>" failures="<%= number_of_failures %>">
8
8
  <% @results.each do |testsuite| %>
9
- <testsuite name=<%= testsuite[:target_name].encode(:xml => :attr) %> tests="<%= testsuite[:number_of_tests] %>" failures="<%= testsuite[:number_of_failures] %>">
9
+ <testsuite name=<%= testsuite[:target_name].encode(:xml => :attr) %> tests="<%= testsuite[:number_of_tests] %>" failures="<%= testsuite[:number_of_failures] %>" time="<%= testsuite[:duration] %>">
10
10
  <% testsuite[:tests].each do |test| %>
11
- <testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %>>
11
+ <testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %> time="<%= test[:duration] %>">
12
12
  <% (test[:failures] || []).each do |failure| %>
13
13
  <failure message=<%= failure[:failure_message].encode(:xml => :attr) %>>
14
14
  </failure>
@@ -47,7 +47,7 @@ module Trainer
47
47
 
48
48
  self.file_content = File.read(path)
49
49
  self.raw_json = Plist.parse_xml(self.file_content)
50
- return if self.raw_json["FormatVersion"].to_s.length == 0 # maybe that's a useless plist file
50
+ return if self.raw_json["FormatVersion"].to_s.length.zero? # maybe that's a useless plist file
51
51
 
52
52
  ensure_file_valid!
53
53
  parse_content
@@ -60,7 +60,7 @@ module Trainer
60
60
 
61
61
  # @return [Bool] were all tests successful? Is false if at least one test failed
62
62
  def tests_successful?
63
- self.data.collect { |a| a[:number_of_failures] }.all? { |a| a == 0 }
63
+ self.data.collect { |a| a[:number_of_failures] }.all?(&:zero?)
64
64
  end
65
65
 
66
66
  private
@@ -71,42 +71,45 @@ module Trainer
71
71
  UI.user_error!("Format version '#{format_version}' is not supported, must be #{supported_versions.join(', ')}") unless supported_versions.include?(format_version)
72
72
  end
73
73
 
74
- # Convert the Hashes and Arrays in something more useful
75
- def parse_content
76
- def unfold_tests(data)
77
- # `data` looks like this
78
- # => [{"Subtests"=>
79
- # [{"Subtests"=>
80
- # [{"Subtests"=>
81
- # [{"TestIdentifier"=>"Unit/testExample()",
82
- # "TestName"=>"testExample()",
83
- # "TestObjectClass"=>"IDESchemeActionTestSummary",
84
- # "TestStatus"=>"Success",
85
- # "TestSummaryGUID"=>"4A24BFED-03E6-4FBE-BC5E-2D80023C06B4"},
86
- # {"FailureSummaries"=>
87
- # [{"FileName"=>"/Users/krausefx/Developer/themoji/Unit/Unit.swift",
88
- # "LineNumber"=>34,
89
- # "Message"=>"XCTAssertTrue failed - ",
90
- # "PerformanceFailure"=>false}],
91
- # "TestIdentifier"=>"Unit/testExample2()",
92
-
93
- tests = []
94
- data.each do |current_hash|
95
- if current_hash["Subtests"]
96
- tests += unfold_tests(current_hash["Subtests"])
97
- end
98
- if current_hash["TestStatus"]
99
- tests << current_hash
100
- end
74
+ # Converts the raw plist test structure into something that's easier to enumerate
75
+ def unfold_tests(data)
76
+ # `data` looks like this
77
+ # => [{"Subtests"=>
78
+ # [{"Subtests"=>
79
+ # [{"Subtests"=>
80
+ # [{"Duration"=>0.4,
81
+ # "TestIdentifier"=>"Unit/testExample()",
82
+ # "TestName"=>"testExample()",
83
+ # "TestObjectClass"=>"IDESchemeActionTestSummary",
84
+ # "TestStatus"=>"Success",
85
+ # "TestSummaryGUID"=>"4A24BFED-03E6-4FBE-BC5E-2D80023C06B4"},
86
+ # {"FailureSummaries"=>
87
+ # [{"FileName"=>"/Users/krausefx/Developer/themoji/Unit/Unit.swift",
88
+ # "LineNumber"=>34,
89
+ # "Message"=>"XCTAssertTrue failed - ",
90
+ # "PerformanceFailure"=>false}],
91
+ # "TestIdentifier"=>"Unit/testExample2()",
92
+
93
+ tests = []
94
+ data.each do |current_hash|
95
+ if current_hash["Subtests"]
96
+ tests += unfold_tests(current_hash["Subtests"])
97
+ end
98
+ if current_hash["TestStatus"]
99
+ tests << current_hash
101
100
  end
102
- return tests
103
101
  end
102
+ return tests
103
+ end
104
104
 
105
+ # Convert the Hashes and Arrays in something more useful
106
+ def parse_content
105
107
  self.data = self.raw_json["TestableSummaries"].collect do |testable_summary|
106
108
  summary_row = {
107
109
  project_path: testable_summary["ProjectPath"],
108
110
  target_name: testable_summary["TargetName"],
109
111
  test_name: testable_summary["TestName"],
112
+ duration: testable_summary["Tests"].map { |current_test| current_test["Duration"] }.inject(:+),
110
113
  tests: unfold_tests(testable_summary["Tests"]).collect do |current_test|
111
114
  current_row = {
112
115
  identifier: current_test["TestIdentifier"],
@@ -114,7 +117,8 @@ module Trainer
114
117
  name: current_test["TestName"],
115
118
  object_class: current_test["TestObjectClass"],
116
119
  status: current_test["TestStatus"],
117
- guid: current_test["TestSummaryGUID"]
120
+ guid: current_test["TestSummaryGUID"],
121
+ duration: current_test["Duration"]
118
122
  }
119
123
  if current_test["FailureSummaries"]
120
124
  current_row[:failures] = current_test["FailureSummaries"].collect do |current_failure|
@@ -1,4 +1,4 @@
1
1
  module Trainer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  DESCRIPTION = "Convert xcodebuild plist files to JUnit reports"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trainer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastlane_core
@@ -158,8 +158,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.5.1
161
+ rubygems_version: 2.6.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Convert xcodebuild plist files to JUnit reports
165
165
  test_files: []
166
+ has_rdoc: