class InspecPlugins::JUnitReporter::ReporterV1

This is the “Legacy” JUnit reporter. It produces XML which is not correct according to the JUnit standard. It is retained for backwards compatibility.

Public Instance Methods

build_profile_xml(profile, _idx) click to toggle source
# File lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb, line 60
def build_profile_xml(profile, _idx)
  profile_xml = REXML::Element.new("testsuite")
  profile_xml.add_attribute("name", profile.name)
  profile_xml.add_attribute("tests", count_profile_tests(profile))
  profile_xml.add_attribute("failed", count_profile_failed_tests(profile))
  profile_xml.add_attribute("failures", count_profile_failed_tests(profile))

  profile.controls.each do |control|
    control.results.each do |result|
      profile_xml.add(build_result_xml(profile.name, control, result))
    end
  end

  profile_xml
end
build_result_xml(profile_name, control, result) click to toggle source
# File lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb, line 76
def build_result_xml(profile_name, control, result)
  result_xml = REXML::Element.new("testcase")
  result_xml.add_attribute("name", result.code_desc)
  result_xml.add_attribute("classname", control.title.nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control.id}")
  result_xml.add_attribute("target", run_data.platform.target.nil? ? "" : run_data.platform.target.to_s)
  result_xml.add_attribute("time", result.run_time)

  if result.status == "failed"
    failure_element = REXML::Element.new("failure")
    failure_element.add_attribute("message", result[:message])
    result_xml.add(failure_element)
  elsif result.status == "skipped"
    result_xml.add_element("skipped")
  end

  result_xml
end