# Using the Testify toolkit

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/2026.3/llms.txt).

The `github.com/stretchr/testify` package is a popular Go library used for writing unit tests. It provides a set of tools like assertions, mocks, and suites that make it easier to write tests in Go. With Testify, you can run your suites and methods as regular test functions. For more information about the toolkit, refer to the description of [Testify on GitHub](https://github.com/stretchr/testify).

In a [Go module](create-a-project-with-go-modules-integration.html), create `main.go` with the following function, then generate a test for it:

```GO
package math

// Add returns the sum of two integers.
func Add(a, b int) int {
	return a + b
}
```

Procedure: Generate a test for package

1. Open a Go file for which you want to generate a test.

2. In the main menu, click `Code | Generate`.

3. In the Generate pop-up window, select Tests for package.

GoLand creates `main_test.go` with a table-driven test template.

![Generate a test for package](https://resources.jetbrains.com/help/img/idea/2026.3/go_generate_a_test_for_package.png)

Modify the generated test so it uses the testify toolkit. Consider the following code snippet for the test.

```GO
package math

import (
  "github.com/stretchr/testify/assert"
  "testing"
)

func TestAdd(t *testing.T) {
  type args struct {
    a int
    b int
  }
  tests := []struct {
    name string
    args args
    want int
  }{
    {"add positives", args{1, 2}, 3},
    {"add negatives", args{-1, -2}, -3},
    {"add positive and negative", args{-1, 1}, 1},
    {"add zeros", args{0, 0}, 0},
  }
  for _, tt := range tests {
    t.Run(tt.name, func(t *testing.T) {
      result := Add(tt.args.a, tt.args.b)
      assert.Equal(t, tt.want, result, "they should be equal")
    })
  }
}
```

The test imports `github.com/stretchr/testify/assert`. If your module does not yet include Testify, resolve the missing dependency:

Procedure: Synchronize missing dependencies

1. Click the import declaration that is missing.

2. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Ctrl+.` (VSCode), `⌘ .` (VSCode (macOS)) and select Fix missing dependencies.

![Syncronize missing dependencies](https://resources.jetbrains.com/help/img/idea/2026.3/go_syncronize_missing_dependencies.png)

Procedure: Run tests with testify

* Click the Run test icon ![The Run test icon](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.execute.svg) and select Run <configuration>.

You can also run individual table tests if desired.

![Run tests with Testify](https://resources.jetbrains.com/help/img/idea/2026.3/go_run_testify.png)

Procedure: Compare expected and actual values

You can compare expected and actual values for failed assertion tests.

* You can compare expected and actual values for failed assertion tests. To see the difference, click the Click to see difference link in the Run pane.

![Compare expected and actual values](https://resources.jetbrains.com/help/img/idea/2026.3/go_compare_expected_actual_results.png)

* Right-click the failed test and select View Differences. Alternatively, press `Ctrl+D` (Windows), `⌘ D` (macOS), `⌘ D` (IntelliJ IDEA Classic (macOS)), `⌘ D` (macOS System Shortcuts), `Ctrl+D` (XWin), `Ctrl+D` (GNOME), `Ctrl+D` (KDE), `Ctrl+D` (Emacs), `Ctrl+D` (Sublime Text), `⌘ D` (Sublime Text (macOS)), `Ctrl+D` (VSCode), `Ctrl+D` (VSCode (macOS)).

![Compare expected and actual values](https://resources.jetbrains.com/help/img/idea/2026.3/go_compare_expected_actual_results_context_menu.png)

