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

是否可以将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.

  • 写回答

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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?