关于 Jenkins JUnit XML 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11530955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:35:34  来源:igfitidea点击:

About Jenkins JUnit XML Format

xmljunitjenkins

提问by G3Y

I'm working on a script that generates test results in JUnit XML format that Jenkins accepts.

我正在编写一个脚本,该脚本以 Jenkins 接受的 JUnit XML 格式生成测试结果。

I read through some answers in StackOverFlow about this topic: JUnit XML format specification that Hudson supportsand Spec. for JUnit XML Outputbut none of these talks about the detail of the "testsuites" attributes or options.

我在 StackOverFlow 中阅读了有关此主题的一些答案:Hudson 支持的 JUnit XML 格式规范规范。用于 JUnit XML 输出,但这些都没有讨论“测试套件”属性或选项的细节。

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>

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!

任何帮助将不胜感激!

回答by malenkiy_scot

I think that information will be automatically computed by Jenkins. If not - don't bother adding it, it won't be displayed anyway.

我认为该信息将由 Jenkins 自动计算。如果没有 - 不要费心添加它,它无论如何都不会显示。

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.xmlin 'Test report XMLs' edit box. Run the job once - that will create its workspace. Now place valid jUnit.xmlthat you want to test in the workspace. Run the job again and examine how test results look.

这里有一个关于如何调试这类事情的有用提示:在 shell/批处理构建步骤中创建一个“接触”文件(我们称之为jUnit.xml)的作业(我们将其命名为jUnitReport);添加“发布 JUnit 测试结果报告”并在“测试报告 XMLs”编辑框中指定jUnit.xml。运行一次作业 - 这将创建其工作区。现在将要测试的有效jUnit.xml 放入工作区。再次运行作业并检查测试结果的外观。

It is important not to remove the 'touch' step - otherwise Jenkins will think of the test results as stale and fail the build.

重要的是不要删除“触摸”步骤 - 否则 Jenkins 会认为测试结果过时并导致构建失败。

You can now play with jUnit.xmlwithout running actual tests and examine how it affects results Jenkins displays.

您现在可以在不运行实际测试的情况下使用jUnit.xml并检查它如何影响 Jenkins 显示的结果。

回答by Nish

I have done this in python. So I can tell you in python. import a package called xmlrunner

我已经在 python 中完成了这个。所以我可以用python告诉你。导入一个名为 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)

现在在您的 jenkins 机器中转到 Post-build Actions 单击 Publish JUnit test result report 旁边的复选框并提供 xml 文件的路径名。(**/test.xml)

you should save-build and the check your detailed results. Hope it helps.

您应该保存构建并检查您的详细结果。希望能帮助到你。

回答by Goutham

Not sure if you found what you are looking for. But the following sample works for me.

不确定您是否找到了您要找的东西。但以下示例对我有用。

<testsuites tests="38" failures="2" disabled="0" errors="0" time="10.898" name="AllTests">
    <!-- Add test suite and other stuff here-->
</testsuites>

Here is what Jenkins supports. Not sure if it is the same for Hudson. https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4.xsd

这是詹金斯支持的内容。不确定哈德森是否也一样。 https://svn.jenkins-ci.org/trunk/hudson/dtkit/dtkit-format/dtkit-junit-model/src/main/resources/com/thalesgroup/dtkit/junit/model/xsd/junit-4。 xsd

回答by Larry Cai

I am looking for the similar things, and mostly it is not possible to use default junit plugin, it doesn't parse this information

我正在寻找类似的东西,而且大多数情况下不可能使用默认的 junit 插件,它不解析这些信息

You can check the source code https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/tasks/junit/SuiteResult.java#L125for this plugin.

您可以查看此插件的源代码https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/tasks/junit/SuiteResult.java#L125

You can fork the junit plugin and extend it.

您可以 fork junit 插件并扩展它。