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 +4 -4
- data/README.md +11 -12
- data/lib/assets/junit.xml.erb +2 -2
- data/lib/trainer/test_parser.rb +35 -31
- data/lib/trainer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4fdc3ecab3134a832020e1df9dd3ec99d8051e1
|
4
|
+
data.tar.gz: 54bc13c8d9eeec5cae850bb244a524c73e73e748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: | :
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
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:
|
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
|
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
|
|
data/lib/assets/junit.xml.erb
CHANGED
@@ -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>
|
data/lib/trainer/test_parser.rb
CHANGED
@@ -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
|
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?
|
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
|
-
#
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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|
|
data/lib/trainer/version.rb
CHANGED
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.
|
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-
|
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.
|
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:
|