douxia2053 2017-06-02 05:00
浏览 463
已采纳

使用Go Test(golang)查找失败的测试文件名

When a Go unit test fails "go test" will display a message like:

--- FAIL: TestFillDeepStruct (0.00s)

But what is the name of the file (in this case Deep_test.go) containing the failing test. I can find no option to "go test" to do this. I have many test files and it is tedious to grep for the test function name.

  • 写回答

1条回答 默认 最新

  • duangai9678 2017-06-02 06:25
    关注

    Use -v (verbose) flag:

    » go test -v example                                                                                                                                         === RUN   TestReturn
    --- FAIL: TestReturn (0.00s)
        ex_test.go:10: /home/user/go/src/example
        ex_test.go:11: Expected 42, got 43
    FAIL
    exit status 1
    FAIL    example 0.002s
    

    In case there are some tests that will not show error line, you may use a this simple bash function:

    function find_failed_tests(){
        FAIL_FILE="/tmp/failed.tmp"
        go test example | grep "^--- FAIL" | awk '{print $3}' > $FAIL_FILE
        grep -rf $FAIL_FILE  ~/go/src/$1
        rm -rf $FAIL_FILE
    }
    
    # Usage:
    find_failed_tests example
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?