test-unit-runner-junitxml 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/lib/test/unit/runner/junitxml.rb +17 -0
- data/lib/test/unit/runner/junitxml/version.rb +9 -0
- data/lib/test/unit/ui/junitxml/testrunner.rb +152 -0
- data/lib/test/unit/ui/junitxml/xml.erb +33 -0
- data/test-unit-runner-junitxml.gemspec +30 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 701cf2bc13f6f5c82a5907bfab0d37c4af45dad3
|
4
|
+
data.tar.gz: d49eab3c3dee6ed2b0b7559024368cff79917a83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 296147c324d43ebf138c1db60bf0f2b1f260e07a1a01fd42a62b0a80910ef643146c7476a9bda67be77d0f29e070d5f95d2792c68db236939aedafd30543f5e3
|
7
|
+
data.tar.gz: 14512b3671114d09568b8c97650d3a309f6e2ba332873e79a6f0ce56b0eecec7a4f6af21377fe967382bc8c9753087d70c78e00f8b415cb3cf6da4fe64d5a555
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 OGAWA KenIchi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "test/unit/autorunner"
|
2
|
+
|
3
|
+
module Test
|
4
|
+
module Unit
|
5
|
+
AutoRunner.register_runner(:junitxml) do |auto_runner|
|
6
|
+
require 'test/unit/ui/junitxml/testrunner'
|
7
|
+
Test::Unit::UI::JUnitXml::TestRunner
|
8
|
+
end
|
9
|
+
|
10
|
+
AutoRunner.setup_option do |auto_runner, opts|
|
11
|
+
opts.on("--junitxml-output-file=FILE_NAME",
|
12
|
+
"Outputs to FILE_NAME") do |name|
|
13
|
+
auto_runner.runner_options[:junitxml_output_file] = name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'test/unit/ui/testrunner'
|
3
|
+
require 'test/unit/ui/testrunnermediator'
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module Unit
|
7
|
+
module UI
|
8
|
+
module JUnitXml
|
9
|
+
|
10
|
+
# Runs a Test::Unit::TestSuite and outputs JUnit XML format.
|
11
|
+
class TestRunner < UI::TestRunner
|
12
|
+
include ERB::Util
|
13
|
+
|
14
|
+
def initialize(suite, options={})
|
15
|
+
super
|
16
|
+
@junit_test_suites = []
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def attach_to_mediator
|
22
|
+
@mediator.add_listener(TestSuite::STARTED_OBJECT,
|
23
|
+
&method(:test_suite_started))
|
24
|
+
@mediator.add_listener(TestSuite::FINISHED_OBJECT,
|
25
|
+
&method(:test_suite_finished))
|
26
|
+
@mediator.add_listener(TestCase::STARTED_OBJECT,
|
27
|
+
&method(:test_started))
|
28
|
+
@mediator.add_listener(TestCase::FINISHED_OBJECT,
|
29
|
+
&method(:test_finished))
|
30
|
+
@mediator.add_listener(TestResult::PASS_ASSERTION,
|
31
|
+
&method(:result_pass_assertion))
|
32
|
+
@mediator.add_listener(TestResult::FAULT,
|
33
|
+
&method(:result_fault))
|
34
|
+
@mediator.add_listener(TestRunnerMediator::FINISHED,
|
35
|
+
&method(:finished))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_suite_started(suite)
|
39
|
+
if suite.test_case
|
40
|
+
@junit_test_suites << JUnitTestSuite.new(suite.name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_suite_finished(suite)
|
45
|
+
if suite.test_case
|
46
|
+
@junit_test_suites.last.time = suite.elapsed_time
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_started(test)
|
51
|
+
@junit_test_suites.last << JUnitTestCase.new(test.class.name,
|
52
|
+
test.description)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_finished(test)
|
56
|
+
@junit_test_suites.last.test_cases.last.time = test.elapsed_time
|
57
|
+
end
|
58
|
+
|
59
|
+
def result_pass_assertion(result)
|
60
|
+
@junit_test_suites.last.test_cases.last.assertion_count += 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def result_fault(fault)
|
64
|
+
@junit_test_suites.last.test_cases.last << fault
|
65
|
+
end
|
66
|
+
|
67
|
+
def finished(elapsed_time)
|
68
|
+
# open ERB template
|
69
|
+
template = File.read(File.expand_path("xml.erb",
|
70
|
+
File.dirname(__FILE__)))
|
71
|
+
if ERB.instance_method(:initialize).parameters.assoc(:key)
|
72
|
+
erb = ERB.new(template, trim_mode: "%")
|
73
|
+
else
|
74
|
+
erb = ERB.new(template, nil, "%")
|
75
|
+
end
|
76
|
+
|
77
|
+
# output
|
78
|
+
output = if @options[:junitxml_output_file]
|
79
|
+
File.open(@options[:junitxml_output_file], "w")
|
80
|
+
elsif @options[:output_file_descriptor]
|
81
|
+
IO.new(@options[:output_file_descriptor], "w")
|
82
|
+
elsif @options[:output]
|
83
|
+
@options[:output]
|
84
|
+
else
|
85
|
+
STDOUT
|
86
|
+
end
|
87
|
+
output.write(erb.result(binding))
|
88
|
+
output.flush
|
89
|
+
output.close if @options[:junitxml_output_file]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class JUnitTestSuite
|
94
|
+
attr_reader :name, :test_cases
|
95
|
+
attr_accessor :time
|
96
|
+
|
97
|
+
def initialize(name)
|
98
|
+
@name = name
|
99
|
+
@time = 0
|
100
|
+
@test_cases = []
|
101
|
+
end
|
102
|
+
|
103
|
+
def <<(test_case)
|
104
|
+
@test_cases << test_case
|
105
|
+
end
|
106
|
+
|
107
|
+
def failures
|
108
|
+
@test_cases.map(&:failure).compact
|
109
|
+
end
|
110
|
+
|
111
|
+
def errors
|
112
|
+
@test_cases.map(&:error).compact
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class JUnitTestCase
|
117
|
+
attr_reader :class_name, :name
|
118
|
+
attr_reader :failure, :error, :omission, :pending
|
119
|
+
attr_accessor :assertion_count, :time
|
120
|
+
|
121
|
+
def initialize(class_name, name)
|
122
|
+
@class_name = class_name
|
123
|
+
@name = name
|
124
|
+
@assertion_count = 0
|
125
|
+
@time = 0
|
126
|
+
@omission = nil
|
127
|
+
@pending = nil
|
128
|
+
end
|
129
|
+
|
130
|
+
def <<(fault)
|
131
|
+
# Notification is ignored
|
132
|
+
case fault
|
133
|
+
when Failure
|
134
|
+
@failure = fault
|
135
|
+
when Error
|
136
|
+
@error = fault
|
137
|
+
when Omission
|
138
|
+
@omission = fault
|
139
|
+
when Pending
|
140
|
+
@pending = fault
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def skipped?
|
145
|
+
@omission || @pending
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<testsuites>
|
3
|
+
% @junit_test_suites.each do |test_suite|
|
4
|
+
<testsuite name="<%=h test_suite.name %>"
|
5
|
+
tests="<%=h test_suite.test_cases.size %>"
|
6
|
+
errors="<%=h test_suite.errors.size %>"
|
7
|
+
failures="<%=h test_suite.failures.size %>"
|
8
|
+
skipped="<%=h test_suite.test_cases.count(&:skipped?) %>"
|
9
|
+
time="<%=h test_suite.time %>">
|
10
|
+
% test_suite.test_cases.each do |test_case|
|
11
|
+
<testcase classname="<%=h test_case.class_name %>"
|
12
|
+
name="<%=h test_case.name %>"
|
13
|
+
time="<%=h test_case.time %>"
|
14
|
+
assertions="<%=h test_case.assertion_count %>">
|
15
|
+
% if test_case.error
|
16
|
+
<error message="<%=h test_case.error.message %>"
|
17
|
+
type="<%=h test_case.error.exception.class.name %>">
|
18
|
+
<%=h test_case.error.long_display %>
|
19
|
+
</error>
|
20
|
+
% elsif test_case.failure
|
21
|
+
<failure message="<%=h test_case.failure.message %>">
|
22
|
+
<%=h test_case.failure.long_display %>
|
23
|
+
</failure>
|
24
|
+
% elsif test_case.omission
|
25
|
+
<skipped message="<%=h test_case.omission.message %>"/>
|
26
|
+
% elsif test_case.pending
|
27
|
+
<skipped message="<%=h test_case.pending.message %>"/>
|
28
|
+
% end
|
29
|
+
</testcase>
|
30
|
+
% end
|
31
|
+
</testsuite>
|
32
|
+
% end
|
33
|
+
</testsuites>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "test/unit/runner/junitxml/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "test-unit-runner-junitxml"
|
8
|
+
spec.version = Test::Unit::Runner::Junitxml::VERSION
|
9
|
+
spec.authors = ["OGAWA KenIchi"]
|
10
|
+
spec.email = ["kenichi@ice.email.ne.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{A test-unit runner that reports test result in JUnit XML format.}
|
13
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
#spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
#spec.bindir = "exe"
|
23
|
+
#spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "test-unit", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test-unit-runner-junitxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OGAWA KenIchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- kenichi@ice.email.ne.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/test/unit/runner/junitxml.rb
|
69
|
+
- lib/test/unit/runner/junitxml/version.rb
|
70
|
+
- lib/test/unit/ui/junitxml/testrunner.rb
|
71
|
+
- lib/test/unit/ui/junitxml/xml.erb
|
72
|
+
- test-unit-runner-junitxml.gemspec
|
73
|
+
homepage:
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.5.2.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A test-unit runner that reports test result in JUnit XML format.
|
97
|
+
test_files: []
|