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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog