将Go测试输出转换为XUnit格式。

huangapple go评论79阅读模式
英文:

Converting Go testing output to XUnit

问题

你好!你可以使用第三方工具来将Go的测试库输出转换为XUnit格式,以便与Jenkins集成。你可以尝试使用go-junit-report工具,它可以将Go测试的输出转换为JUnit XML格式。你可以按照以下步骤进行操作:

  1. 首先,确保你已经安装了go-junit-report工具。你可以使用以下命令进行安装:

    go get -u github.com/jstemmer/go-junit-report
    
  2. 运行你的Go测试,并将输出重定向到一个文件中,例如:

    go test -v ./... > test_output.txt
    
  3. 使用go-junit-report工具将测试输出转换为XUnit格式的XML文件:

    cat test_output.txt | go-junit-report > test_output.xml
    
  4. 现在,你可以将生成的test_output.xml文件用作Jenkins的测试报告。在Jenkins的构建配置中,你可以添加一个"Publish JUnit test result report"的后置操作,并指定test_output.xml文件的路径。

这样,你就可以将Go的测试输出以XUnit格式展示在Jenkins中了。希望对你有帮助!如果有任何其他问题,请随时提问。

英文:

How can I have the output of Go's testing library output in XUnit format for integration with Jenkins? There are no command line options to output to XML or to XUnit format with go test.

答案1

得分: 11

有一个很好的小插件可以进行转换:https://github.com/tebeka/go2xunit

安装方法如下:

go get github.com/tebeka/go2xunit

使用方法如下:

# 像平常一样运行你的测试,但将详细输出导入转换器
go test -v | $GOPATH/bin/go2xunit > test_output.xml

如果你的正常 $PATH 中包含 $GOPATH/bin

go test -v | go2xunit > test_output.xml
英文:

There's a nice little plugin to convert: https://github.com/tebeka/go2xunit

To install it:

go get github.com/tebeka/go2xunit

To use it:

# Run your tests like normal, but pipe the verbose output to the converter
go test -v | $GOPATH/bin/go2xunit > test_output.xml

If you have $GOPATH/bin in your normal $PATH:

go test -v | go2xunit > test_output.xml

huangapple
  • 本文由 发表于 2014年1月7日 04:26:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/20958647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定