Class: Minitest::Reporters::JUnitReporter

Inherits:
BaseReporter
  • Object
show all
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)

Instance Attribute Summary

Attributes inherited from BaseReporter

#tests

Instance Method Summary collapse

Methods inherited from BaseReporter

#add_defaults, #after_test, #before_test, #record

Constructor Details

#initialize(reports_dir = "test/reports", empty = true, options = {}) ⇒ JUnitReporter

Returns a new instance of JUnitReporter.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/minitest/reporters/junit_reporter.rb', line 12

def initialize(reports_dir = "test/reports", empty = true, options = {})
  super({})
  @reports_path = File.absolute_path(reports_dir)
  @single_file = options[:single_file]

  if empty
    puts "Emptying #{@reports_path}"
    FileUtils.mkdir_p(@reports_path)
    File.delete(*Dir.glob("#{@reports_path}/TEST-*.xml"))
  end
end

Instance Method Details

#report



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/minitest/reporters/junit_reporter.rb', line 24

def report
  super

  puts "Writing XML reports to #{@reports_path}"
  suites = tests.group_by(&:class)

  if @single_file
    write_xml_file_for("minitest", tests.group_by(&:class).values.flatten)
  else
    suites.each do |suite, tests|
      write_xml_file_for(suite, tests)
    end
  end

end