在詹金斯中使用gtest [英] Using gtest in jenkins

查看:549
本文介绍了在詹金斯中使用gtest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在詹金斯(Jenkins)中成功使用Google测试运行了单元测试,但是我不知道如何显示由gtest生成的.xml文件.据说gtest满足JUnit格式,所以我设置如下:

I successfully run my unit test with google test in Jenkins, but I don't know how to show the .xml file generated by gtest. It is said that gtest satisfies the JUnit format, so what I set is as follows:

但是最终在构建后会出现错误.

But it ends up with errors after a building.

未找到测试报告文件.配置错误?
构建步骤发布JUnit测试结果报告"将构建结果更改为FAILURE
完成:失败

No test report files were found. Configuration error?
Build step 'Publish JUnit test result report' changed build result to FAILURE
Finished: FAILURE

推荐答案

Fraser的回答很好,您需要进行一些额外的处理才能将gtest XML转换为正确的JTest格式.

Fraser's answer is good and you need some extra processing to convert the gtest XML to proper JTest format.

首先,您要求gtest使用以下命令将结果输出到XML:

First you ask gtest to output the result to XML using:

mygtestapp --gtest_output=xml:gtestresults.xml

然后在脚本中,您需要添加额外的元素以正确地标记跳过的测试. Jenkin的JTest处理器要求跳过的测试包含< skipped>元素,而不仅仅是将状态设置为非运行":

Then in a script you need to add extra elements to properly flag skipped tests as such. Jenkin's JTest processor requires that a skipped test contains the <skipped> element and not just setting status to "notrun":

awk '{ if ($1 == "<testcase" && match($0, "notrun")) print substr($0,0,length($0)-2) "><skipped/></testcase>"; else print $0;}' gtestresults.xml > gtestresults-skipped.xml
mv gtestresults.xml gtestresults.off

如果在Windows批处理文件上运行此命令,请将awk操作放入文件中以避免引号引起问题. awk.progfile:

If running this on a windows batch file, put the awk action inside a file to avoid problems with the quotes. awk.progfile:

{ if ($1 == "<testcase" && match($0, "notrun")) print substr($0,0,length($0)-2) "><skipped/></testcase>"; else print $0;}

并在bat文件中创建添加项:

And create add in your bat file:

awk -f awk.progfile gtestresults.xml > gtestresults-skipped.xml

最后,您将JTest处理器指向一个Post-Build步骤,以读取转换后的XML:

Lastly you point the JTest processor as a Post-Build step to read the converted XML:

# Publish JUnit Test Result Report
Test Report XMLs: gtestresults-skipped.xml

这篇关于在詹金斯中使用gtest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆