Skip to content
| Marketplace
Sign in
Visual Studio Code>Debuggers>Go Test CodeLens - EnhancedNew to Visual Studio Code? Get it now.
Go Test CodeLens - Enhanced

Go Test CodeLens - Enhanced

Tim Weightman

|
179 installs
| (1) | Free
Go Test CodeLens - Run and Debug table-driven tests
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Go Test CodeLens - Enhanced

Run and debug Go table-driven tests in VS Code, using CodeLens hints above the table-driven test names.

CodeLens support for table-driven tests

This extension:

  1. Can handle any structured slice or map.
  2. Does not require any specific property naming - it will work with variable names or struct field names that you pass to t.Run as the first ("name") argument.

Relies on the Go for Visual Studio Code extension.

Run test | Debug test - both supported, for individual table-driven test scenarios.

🗺️ Maps

table := map[string]string{
  // run test | debug test      <-- CodeLens run/debug "test name one"
  "test name one": "whatever",
  // run test | debug test      <-- CodeLens run/debug "test name two"
  "test name two": "whatever",
}

for k, v := range table {
  t.Run(k, func(t *testing.T) {
    t.Parallel()
    fmt.Println(k, v)
  })
}

🍞 Slices

table := []struct {
  stuff string // <-- Arbitrary test name given as t.Run(v.stuff, ...)
  value string
}{
  {
    // run test | debug test      <-- CodeLens run/debug "test name one"
    stuff: "test name one",
    value: "value1",
  },
  {
    // run test | debug test      <-- CodeLens run/debug "test name two"
    stuff: "test name two",
    value: "value2",
  },
}

for _, v := range table {
  t.Run(v.stuff, func(t *testing.T) {
    t.Parallel()
    fmt.Println(v.stuff, v.value)
  })
}

🦹 What are you doing, you monster! (but it does work) 🙈

mTable := map[string]string{
  // run test | debug test      <-- CodeLens run/debug "test name one"
  "test name one": "value1",
  // run test | debug test      <-- CodeLens run/debug "test name two"
  "test name two": "value2",
}
sTable := []struct {
  name  string
  value string
}{
  {
    // run test | debug test      <-- CodeLens run/debug "test name one#01"
    name:  "test name one",
    value: "value1",
  },
  {
    // run test | debug test      <-- CodeLens run/debug "test name two#01"
    name:  "test name two",
    value: "value2",
  },
}

for k, v := range mTable {
  t.Run(k, func(t *testing.T) {
    t.Parallel()
    fmt.Println(k, v)
  })
}

for _, v := range sTable {
  t.Run(v.name, func(t *testing.T) {
    t.Parallel()
    fmt.Println(v.name, v.value)
  })
}

How you can use it

  1. Open any Go test file (*_test.go)
  2. Find any slice- or map-based table-driven tests
  3. Look for the run test | debug test CodeLens above the test name
  4. Click, and watch the magic unfold 🧙 ✨ 🧪 🎯

Requirements

This extension requires the Go for Visual Studio Code extension to be installed.

Future enhancements

  • Should I look at integrating with VS Code's Test Explorer for a more native test running experience?

Installation

You can install from here.

Credits

Loosely based on the work of takaaa220 - thanks!

License

Apache License Version 2.0

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft