Easily debug table driven tests in Golang + VSCode

Or, how to run single test cases in table driven testing.

Easily debug table driven tests in Golang + VSCode

Have you even wanted to run a single test case in VSCode when doing table driven testing, but found out that there is no simple way to do so?

Sure, you can press "run test" and change the results manually, but this will mean you need to run the entire test case.

Wouldn't it be much easier to simply run one test case in the table?

Well, you actually can.

Go: Debug Subtest at Cursor

This allows you to specify a subtest to run based on the name. So as long as your table driven test case has dynamic names, this will allow you to select specific test cases.

Steps:

  1. Place cursor on the table driven test cases

  2. press cmd + shift + p

  3. type in: Go: Debug Subtest at Cursor

  4. Press enter

  5. Type in the name of the test case.

  6. Check the Debug Console. Done!

Screenshots:

I hope this helps someone out there :)