Golang – Debug a unit test manually

Encountered a tricky problem – unit tests completed without any errors when ran them using IDE, but when ran from the console, one of the tests was failing. I won’t go into the problem details (it was something to do with how IDE allocates /dev/tty device), however will give instructions how to debug a failing test mnually. Golang tests are little programs. You can compile them separately for every package. For instance, here I’m building a test file for a package located in /internal/app The command above will produce a binary called app.test, which you can run like a separate command Once you have a binary, you can debug your issue as usual in delve: Or you can event run this file within your IDE, here is VS Code launch task example: Have fun with heisenbugs!