Search⌘ K
AI Features

Skipping and Testify Package

Understand how to selectively skip tests in Go with the -short flag and environment conditions to optimize test runs. Explore using the testify/assert package to write cleaner and more efficient test assertions. This lesson equips you with practical techniques to manage tests better while improving code readability.

Skipping tests

Sometimes, we don’t want to execute all of our tests and would instead like to select only the relevant ones for our current needs. Some real-world examples of when this might be the case are:

  • We have extremely long-running tests that should only be run intermittently.
  • We have tests that only have to be run in certain environments (development, test, UAT, production, and so on).
  • We want to exclude some tests in our CI/CD pipeline.
  • We want to exclude some tests that rely on external resources that may not always be reliable or running.

Let’s see two ways for skipping tests that Go provides us.

With the -short flag

The first option is to use ...