Debugging tests with delve

后端 未结 2 641
误落风尘
误落风尘 2021-02-07 15:53

I\'m using \"go test -v\" to run bunch of unit tests. I\'d like to debug them using delve. When I try to run debugger, I get an \"Can not debug non-main

2条回答
  •  庸人自扰
    2021-02-07 16:39

    I'm not familiar with delve, but if it can work on a compiled binary, just compile your tests using the -c flag:

        -c
            Compile the test binary to pkg.test but do not run it
            (where pkg is the last element of the package's import path).
            The file name can be changed with the -o flag.
    

    Then run delve on the output.

提交回复
热议问题