Skipping and Testify Package

Learn about skipping tests and the testify/assert package.

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 the -short flag when running tests from our terminal. This flag says to skip the long-running tests and to only execute the short ones. Let’s see this in action:

Get hands-on with 1400+ tech skills courses.