Class: Rutema::Reporters::JUnit
- Inherits:
-
BlockReporter
- Object
- BlockReporter
- Rutema::Reporters::JUnit
- Defined in:
- lib/rutema/reporters/junit.rb
Overview
This reporter generates an JUnit style XML result file that can be parsed by CI plugins
It has been tested with Jenkins (>1.6.20)
The following configuration keys are used by Rutema::Reporters::JUnit
filename - the filename to use when saving the report. Default is 'rutema.results.junit.xml'
Example configuration:
require "rutema/reporters/junit" cfg.reporter=:class=>Rutema:class=>Rutema::Reporters:class=>Rutema::Reporters::JUnit,"filename"=>"rutema:class=>Rutema::Reporters::JUnit,"filename"=>"rutema.junit:class=>Rutema::Reporters::JUnit,"filename"=>"rutema.junit.xml"
Constant Summary collapse
- DEFAULT_FILENAME =
"rutema.results.junit.xml".freeze
Instance Method Summary collapse
-
#initialize(configuration, dispatcher) ⇒ JUnit
constructor
A new instance of JUnit.
- #process_data(specs, states, errors) ⇒ Object
-
#report(specs, states, errors) ⇒ Object
We get all the data from a test run in here.
Constructor Details
#initialize(configuration, dispatcher) ⇒ JUnit
Returns a new instance of JUnit.
23 24 25 26 |
# File 'lib/rutema/reporters/junit.rb', line 23 def initialize(configuration, dispatcher) super @filename = configuration.reporters.fetch(self.class, {}).fetch("filename", DEFAULT_FILENAME) end |
Instance Method Details
#process_data(specs, states, errors) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rutema/reporters/junit.rb', line 34 def process_data(specs, states, errors) tests = [] number_of_failed = 0 total_duration = 0 states.each do |k, v| tests << test_case(k, v) number_of_failed += 1 if v.status != :success total_duration += v.duration.to_f end # <testsuite disabled="0" errors="0" failures="1" hostname="" id="" # name="" package="" skipped="" tests="" time="" timestamp=""> attributes = { "id" => @configuration.context[:config_name], "name" => @configuration.context[:config_name], "errors" => errors.size, "failures" => number_of_failed, "tests" => specs.size, "time" => total_duration, "timestamp" => @configuration.context[:start_time] } return junit_content(tests, attributes, errors) end |
#report(specs, states, errors) ⇒ Object
We get all the data from a test run in here.
29 30 31 32 |
# File 'lib/rutema/reporters/junit.rb', line 29 def report(specs, states, errors) cnt = process_data(specs, states, errors) Rutema::Utilities.write_file(@filename, cnt) end |