doucong6884
2015-03-19 17:05
浏览 350
已采纳

是否可以将golang单元测试结果打印到文件中?

I run go test in my pkg directory and I get the test results printed to the console as they run, but it would be ideal if I could get them printed to a txt file or even a html file, is it possible to do this? I know you can get coverage reports out from it and generate html files for those which is excellent, but I would have thought it possible to do the same just for the actual results of the tests i.e which tests ran, which passed and which failed. I've been searching the net but even go test help doesn't offer any suggestions for printing results out to a file.

图片转代码服务由CSDN问答提供 功能建议

我在pkg目录中运行 go test ,然后将测试结果打印到 控制台在它们运行时运行,但是如果我可以将它们打印到txt文件甚至html文件中,那将是理想的选择,是否可以这样做? 我知道您可以从中获取覆盖率报告并为出色的报告生成html文件,但是我认为可以对测试的实际结果执行相同的操作,即运行,通过和失败的测试。 我一直在网上搜索,但是即使 go test help 也没有提供任何将结果打印到文件的建议。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwai4434 2015-03-19 17:27
    已采纳

    Since I only want to see failed test, I have this script "gt" that I run instead of go test:

    go test -coverprofile=coverage.out %*|grep -v -e "^\.\.*$"|grep -v "^$"|grep -v "thus far"
    

    That way, it filters everything but the failed cases.
    And you can redirect its content to a file, as mentioned: gt > test.out

    It also generates code coverage, which is why I have another script "gc":

    grep -v -e " 1$" coverage.out
    

    That way, I don't even wait for a brower to open, I directly see the list of lines which are not yet covered (ie, which don't end with '1' in the coverage.out file)

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题