About Jenkins JUnit XML Format
I'm working on a script that generates test results in JUnit XML format that Jenkins accepts.
I read through some answers in StackOverFlow about this topic: JUnit XML format specification that Hudson supports and Spec. for JUnit XML Output but none of these talks about the detail of the "testsuites" attributes or options.
I want to show the total number of "testcase", total number of failed "testcase" and total number of skipped "testcase" from all the "testsuite" under the "testsuites".
ie <testsuites *something to add here to include the info demanded*>...</testsuites>
Is there a way to achieve that?
Any help will be greatly appreciated!
I think that information will be automatically computed by Jenkins. If not - don't bother adding it, it won't be displayed anyway.
Here's a useful tip on how to debug this sort of thing: create a job (let's name it jUnitReport) that "touches" a file (let's call it jUnit.xml) in a shell/batch build step; add 'Publish JUnit test resul report' and specify jUnit.xml in 'Test report XMLs' edit box. Run the job once - that will create its workspace. Now place valid jUnit.xml that you want to test in the workspace. Run the job again and examine how test results look.
It is important not to remove the 'touch' step - otherwise Jenkins will think of the test results as stale and fail the build.
You can now play with jUnit.xml without running actual tests and examine how it affects results Jenkins displays.
I have done this in python. So I can tell you in python. import a package called xmlrunner
import xmlrunner
class ABC(unittest.TestCase)
asserts/tests..
...
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(ABC)
xmlrunner.XMLTestRunner().run(suite)
Now in your jenkins machine go to Post-build Actions Click on the check box next to Publish JUnit test result report and provide the path name to the xml file. (**/test.xml)
you should save-build and the check your detailed results. Hope it helps.
I am looking for the similar things, and mostly it is not possible to use default junit plugin, it doesn't parse this information
You can check the source code https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/tasks/junit/SuiteResult.java#L125 for this plugin.
You can fork the junit plugin and extend it.
链接地址: http://www.djcxy.com/p/11026.html