def write_junit(target = self.class.default_target)
      # Open a File Object for IO if target is a string containing a filename or path
      target = File.open(target, 'w') if target.is_a? String

      document = REXML::Document.new
      document << REXML::XMLDecl.new
      testsuites = REXML::Element.new('testsuites')

      id = 0
      events.each do |testsuite_name, testcases|
        testsuite = REXML::Element.new('testsuite')
        testsuite.attributes['name'] = testsuite_name
        testsuite.attributes['tests'] = testcases.length
        testsuite.attributes['errors'] = testcases.select(&:error?).length
        testsuite.attributes['failures'] = testcases.select(&:failure?).length
        testsuite.attributes['skipped'] = testcases.select(&:skipped?).length
        testsuite.attributes['time'] = 0
        testsuite.attributes['timestamp'] = Time.now.strftime('%Y-%m-%dT%H:%M:%S')
        testsuite.attributes['hostname'] = Socket.gethostname
        testsuite.attributes['id'] = id
        testsuite.attributes['package'] = testsuite_name
        testsuite.add_element('properties')
        testcases.each { |r| testsuite.elements << r.to_junit }
        testsuite.add_element('system-out')
        testsuite.add_element('system-err')

        testsuites.elements << testsuite
        id += 1
      end

      document.elements << testsuites
      document.write(target, 2)
    ensure
      target.close if target.is_a? File
    end
def write_junit(target = self.class.default_target)
      # Open a File Object for IO if target is a string containing a filename or path
      target = File.open(target, 'w') if target.is_a? String

      document = REXML::Document.new
      document << REXML::XMLDecl.new
      testsuites = REXML::Element.new('testsuites')

      id = 0
      events.each do |testsuite_name, testcases|
        testsuite = REXML::Element.new('testsuite')
        testsuite.attributes['name'] = testsuite_name
        testsuite.attributes['tests'] = testcases.length
        testsuite.attributes['errors'] = testcases.select(&:error?).length
        testsuite.attributes['failures'] = testcases.select(&:failure?).length
        testsuite.attributes['skipped'] = testcases.select(&:skipped?).length
        testsuite.attributes['time'] = 0
        testsuite.attributes['timestamp'] = Time.now.strftime('%Y-%m-%dT%H:%M:%S')
        testsuite.attributes['hostname'] = Socket.gethostname
        testsuite.attributes['id'] = id
        testsuite.attributes['package'] = testsuite_name
        testsuite.add_element('properties')
        testcases.each { |r| testsuite.elements << r.to_junit }
        testsuite.add_element('system-out')
        testsuite.add_element('system-err')

        testsuites.elements << testsuite
        id += 1
      end

      document.elements << testsuites
      document.write(target, 2)
    ensure
      target.close if target.is_a? File
    end
Renders the report as a JUnit XML document.

 @param target [#write] an IO object that the report will be written to.
   Defaults to PDK::Report.default_target.