Golang – Debug a unit test manually

I ran into a tricky issue where all unit tests passed when executed from the IDE, but one test consistently failed when run from the command line. I won’t go into the details of the root cause (it was related to how the IDE handles the /dev/tty device), but I will provide instructions on how to manually debug a failing test. 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!