Converting non standard test output to unit test xml

Let’s say a build generates a json file that contains test names and the test results in this form.

{
  "Integration Test1": "Passed",
  "Integration Test2": "Failed",
  "Integration Test3": "Passed"
}

This type of summary won’t be so useful for Jenkins to track and report as a post build process. A simple python based test can convert that to a standard JUnit format xml file.

test/test.py

from nose_parameterized import parameterized, param
import unittest, json

class TestPSRResults(unittest.TestCase):
	def load_results():
		with open('TestResults.json') as f:
			summary_dict = json.load(f)
		print summary_dict
		summary = []
		for name in summary_dict.keys():
			summary.append((name, summary_dict[name]))
		return summary

	@parameterized.expand(load_results)
	def test_result(self, name, result):
		assert result == 'Passed' , "Actual Result : {}".format(result)

unittest.cfg

[unittest]
plugins=nose2.plugins.junitxml

[junit-xml]
always-on=True
test_fullname=True

Configure Jenkins to run this as a build step after the actual test that generates TestResults.json

nose2 -v

Then Jenkins now can publish JUnit test result report for nose2-junit.xml.
JUnitJenkinsChart

changgull