Generating a continuous integration report for Jenkins using NoseXUnit

JUnit (http://junit.org) is a software industry leader in automated testing. It provides the ability to generate XML report files that are consumed by many tools. This extends to continuous tools like Jenkins.

NoseXUnit (http://nosexunit.sourceforge.net/) is a Nose plugin that generates XML reports with Python test results in the same format. It works like JUnit with XML reporting but for unittest. Even though we aren't building Java code, there is no requirement that states our CI server can't be a Java-based system. As long as we can generate the right reports, those tools are candidates for usage. Considering that one of the most popular and well-supported CI systems is Jenkins, this type of plugin is very useful.

With this recipe, we will explore generating consumable reports from simple Python testing.

Getting ready

The following steps are needed to have all the components installed for this chapter.

  1. Install Nose as shown in Chapter 2.
  2. Install NoseXUnit (http://nosexunit.sourceforge.net/) by typing pip install nosexunit.

How to do it...

The following steps will show how to use the NoseXUnit plugin to generate an XML report in a Jenkins-compatible format:

  1. Test the shopping cart application using nosetests and the NoseXUnit plugin by typing nosetests tests.py --with-nosexunit.
    How to do it...
  2. Open the report found in target/NoseXUnit/core/TEST-tests.xml using an XML or text editor. The following screenshot shows the report displayed in SpringSource Tool Suite (http://www.springsource.com/developer/sts), an Eclipse derivative. (This is by no means a recommendation. Many modern IDEs have built-in XML support as do other editors like emacs, textpad, and so on).
    How to do it...

How it works...

NoseXUnit collects the outcome of each test and generates an XML report that has the same format as JUnit. The XML file isn't designed to be human consumable, but it's not too hard to discern the results. When we ran nosetests earlier, how many test cases passed? What were the test method names?

In this XML file, we can see the names of the four test cases. In fact, if this file is opened inside certain tools like the SpringSource Tool Suite, it displays itself as a test outcome.

How it works...

We don't have to use STS to do any of this. In fact, STS is a bit heavyweight for this simple task. Your favorite XML or text editor is fine to inspect the report. I just wanted to demonstrate how the output of this plugin neatly works with existing tools.

By typing nosetests-help, we can see all the options that nose has from all the installed plugins. This includes:

  • --core-target=CORE_TARGET: Output folder for test reports (defaults to target/NoseXUnit/core)
  • --with-nosexunit: Runs it through the plugin
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178