Tagging and Ignoring Tests

Learn how to tag your test suites to run them selectively.

When and why should you tag?

In large projects, the ability to tag tests is fundamental. There are two main reasons to tag a test or a set of tests:

  • Ignoring them

  • Running them selectively

There are several reasons you might want to ignore tests. For example, they might be too slow to run many times, so we might want to exclude them from some test runs to speed up our development. Or perhaps they’re incomplete or target a feature that hasn’t been fully developed yet, or we’re in the middle of a refactoring and don’t want to run tests because we know they won’t pass.

Sometimes it’s easier to run tests selectively. Most IDEs give us the ability to run single test cases or test suites in isolation, but what if we want to run tests that don’t belong to the same suite? In these cases, it’s helpful to be able to run only the tests with a given tag.

ScalaTest supports both scenarios. In this lesson, we’ll learn how to ignore tests and apply tags to them.

Ignoring a test

Each style trait in ScalaTest has a way to specify which test cases to ignore. We can use the ignore keyword to tell ScalaTest to skip the execution of a given test case. The output will state clearly that the test was ignored.

Get hands-on with 1200+ tech skills courses.