Class: XunitOutput
- Inherits:
-
Object
- Object
- XunitOutput
- Defined in:
- lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb
Overview
Creates a XML report that conforms to # svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd
Instance Method Summary collapse
- #add(line) ⇒ Object
- #add_status(status, date, time, time_zone, msg) ⇒ Object
- #close ⇒ Object
-
#initialize(filename) ⇒ XunitOutput
constructor
A new instance of XunitOutput.
- #serialize(suite) ⇒ Object
- #xml_escape(input) ⇒ Object
Constructor Details
#initialize(filename) ⇒ XunitOutput
Returns a new instance of XunitOutput.
59 60 61 62 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 59 def initialize(filename) @filename = filename @suite = TestSuite.new(File.basename(filename, File.extname(filename))) end |
Instance Method Details
#add(line) ⇒ Object
64 65 66 67 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 64 def add(line) return if @suite.test_cases.empty? @suite.test_cases.last << line end |
#add_status(status, date, time, time_zone, msg) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 69 def add_status(status, date, time, time_zone, msg) case status when :start @suite.test_cases << TestCase.new(msg) when :pass @suite.test_cases.last.pass! if @suite.test_cases.last != nil when :fail @suite.test_cases.last.fail! if @suite.test_cases.last != nil else if @suite.test_cases.last != nil && @suite.test_cases.last.time == 0 @suite.test_cases.last << "#{status.to_s.capitalize}: #{msg}" end end end |
#close ⇒ Object
84 85 86 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 84 def close File.open(@filename, 'w') { |f| f.write(serialize(@suite)) } end |
#serialize(suite) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 100 def serialize(suite) output = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" << "\n" output << "<testsuite name=\"#{xml_escape(suite.name)}\" timestamp=\"#{suite.}\" time=\"#{suite.time}\" tests=\"#{suite.test_cases.count}\" failures=\"#{suite.failures}\">" << "\n" suite.test_cases.each do |test| output << " <testcase name=\"#{xml_escape(test.name)}\" time=\"#{test.time}\">" << "\n" if test.failed? output << " <failure>#{test..map { |m| xml_escape(m) }.join("\n")}</failure>" << "\n" end output << " </testcase>" << "\n" end output << "</testsuite>" << "\n" end |
#xml_escape(input) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb', line 88 def xml_escape(input) result = input.dup result.gsub!("&", "&") result.gsub!("<", "<") result.gsub!(">", ">") result.gsub!("'", "'") result.gsub!("\"", """) return result end |