Class: Minitest::Reporters::JUnitReporter
- Inherits:
-
BaseReporter
- Object
- StatisticsReporter
- BaseReporter
- Minitest::Reporters::JUnitReporter
- Defined in:
- lib/minitest/reporters/junit_reporter.rb
Overview
A reporter for writing JUnit test reports Intended for easy integration with CI servers - tested on JetBrains TeamCity
Inspired by ci_reporter (see https://github.com/nicksieger/ci_reporter) Also inspired by Marc Seeger's attempt at producing a JUnitReporter (see https://github.com/rb2k/minitest-reporters/commit/e13d95b5f884453a9c77f62bc5cba3fa1df30ef5) Also inspired by minitest-ci (see https://github.com/bhenderson/minitest-ci)
Constant Summary collapse
- DEFAULT_REPORTS_DIR =
"test/reports"
Instance Attribute Summary collapse
-
#reports_path
readonly
Returns the value of attribute reports_path.
Attributes inherited from BaseReporter
Instance Method Summary collapse
- #get_relative_path(result)
-
#initialize(reports_dir = DEFAULT_REPORTS_DIR, empty = true, options = {}) ⇒ JUnitReporter
constructor
A new instance of JUnitReporter.
- #report
Methods inherited from BaseReporter
#add_defaults, #after_test, #before_test, #record
Constructor Details
#initialize(reports_dir = DEFAULT_REPORTS_DIR, empty = true, options = {}) ⇒ JUnitReporter
Returns a new instance of JUnitReporter.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minitest/reporters/junit_reporter.rb', line 21 def initialize(reports_dir = DEFAULT_REPORTS_DIR, empty = true, = {}) super({}) @reports_path = File.absolute_path(ENV.fetch("MINITEST_REPORTERS_REPORTS_DIR", reports_dir)) @single_file = [:single_file] @base_path = [:base_path] || Dir.pwd = [:include_timestamp] return unless empty puts "Emptying #{@reports_path}" FileUtils.mkdir_p(@reports_path) File.delete(*Dir.glob("#{@reports_path}/TEST-*.xml")) end |
Instance Attribute Details
#reports_path (readonly)
Returns the value of attribute reports_path.
19 20 21 |
# File 'lib/minitest/reporters/junit_reporter.rb', line 19 def reports_path @reports_path end |
Instance Method Details
#get_relative_path(result)
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/minitest/reporters/junit_reporter.rb', line 64 def get_relative_path(result) file_path = Pathname.new(get_source_location(result).first) base_path = Pathname.new(@base_path) if file_path.absolute? file_path.relative_path_from(base_path) else file_path end end |
#report
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/minitest/reporters/junit_reporter.rb', line 35 def report super puts "Writing XML reports to #{@reports_path}" suites = tests.group_by do |test| test_class(test) end if @single_file xml = Builder::XmlMarkup.new(:indent => 2) xml.instruct! xml.testsuites do suites.each do |suite, tests| parse_xml_for(xml, suite, tests) end end File.open(filename_for('minitest'), "w") { |file| file << xml.target! } else suites.each do |suite, tests| xml = Builder::XmlMarkup.new(:indent => 2) xml.instruct! xml.testsuites do parse_xml_for(xml, suite, tests) end File.open(filename_for(suite), "w") { |file| file << xml.target! } end end end |