Skip to content

Ruby Gem to help building test reports in Jenkins CI JUnit XML format.

License

Notifications You must be signed in to change notification settings

hsitter/jenkins_junit_builder

 
 

Repository files navigation

Gem Version

Jenkins CI compatible Junit XML report builder

When you have your own home brewed testing framework but still want to use Jenkins CI with it's standard JUnit plugin, you may find yourself searching for a valid and recent documentation on how to create such XML documents. It's hard. Harder for newbies who want to learn how to set up/use Jenkins and make it useful to their projects.

The XSD schema that serves as a base of the XMLs generated can be found here.

I have put together a blog entry on describing how the XML is interpreted and presented by Jenkins.

Installation

Add this line to your application's Gemfile:

gem 'jenkins_junit_builder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jenkins_junit_builder

Since it uses Nokogiri to build report XMLs, please refer to Nokogiri's documentation for more installation instructions if you run into build errors.

Usage

Please note that understanding how to read an XSD schema (which is not that hard) will really help navigating and understanding what properties are available and how to structure them. Again, Jenkins looks like to work by this XSD schema.

Since we are building our own testing system, I did something that is not soooo magical as a DSL with raibows and Unikitties.

Require the lib:

require 'jenkins_junit_builder'

Let's report a pass:

t_passed           = JenkinsJunitBuilder::Case.new
t_passed.name      = 'My first test case'
t_passed.time      = 65
t_passed.classname = 'FirstTestSuite'
t_passed.result    = JenkinsJunitBuilder::Case::RESULT_PASSED

Then a failure:

t_failed                    = JenkinsJunitBuilder::Case.new
t_failed.name               = 'My failing functionality'
t_failed.classname          = 'FirstTestSuite'
t_failed.result             = JenkinsJunitBuilder::Case::RESULT_FAILURE
t_failed.message            = 'timeout reached'
t_failed.system_out.message = 'some thing went wrong'
t_failed.system_err.message = 'give me a stacktrace or something'

Add those to the suite:

t_suite         = JenkinsJunitBuilder::Suite.new
t_suite.name    = 'Testing some cases'
t_suite.package = 'Mytest'
t_suite.add_case t_passed
t_suite.add_case t_failed

And bake them:

xml_report = t_suite.build_report

Into this:

<testsuites>
  <testsuite name="Testing some cases" package="Mytest">
    <testcase name="My first test case" time="65" classname="Mytest.FirstTestSuite"/>
    <testcase name="My failing functionality" classname="Mytest.FirstTestSuite">
      <failure message="timeout reached"/>
      <system-out>some thing went wrong</system-out>
      <system-err>give me a stacktrace or something</system-err>
    </testcase>
  </testsuite>
</testsuites>

Please refer to the tests and code for more guidance for the time being.

##Heads up

  • do not include a dot (.) in the testcase.name and testsuite.classname, only if you intentionally want extra level indentation within your test hierarchy

##Changelog 0.0.6

  • Simplified require

0.0.5

  • Still learning rubygem dependencies the hard way

0.0.4

  • Added support to package attribute

0.0.3

  • Changed require mechanism to be compatible with JRuby 1.7 (and MRI 1.9.3)

0.0.2

  • Learned that rubygems have their runtime dependency list in the gemspec (A.K.A first working version)

Contributing

  1. Fork it ( https://github.com/vadviktor/jenkins_junit_builder/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Written with StackEdit.

About

Ruby Gem to help building test reports in Jenkins CI JUnit XML format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%