Skip to main content
All Bazel test rules share common attributes that control how tests are executed and how they can be filtered. These attributes are useful for organizing tests by purpose, execution time, and scope.

Common test attributes

Size

The size attribute is an architectural hint. It affects both the default timeout and the amount of system resources Bazel allocates when scheduling the test. Common size values include:

Timeout

You could specify an explicit timeout value, either in addition to or instead of size.
Unfortunately, timeout has an undesirable default value of moderate. It should be the shortest value so that developers are reminded to increase it when a test times out.

Filtering tests

The size attribute is useful for filtering. For example, you can use --test_size_filters=small to ask Bazel to run a unit test. You can also filter with these flags:

Filter by tags

This command runs only tests tagged with smoke.

Filter by timeout

This command will skip running tests that take a long time.
By default, the eternal timeout corresponds to approximately 15 minutes. For details on timeout values and behavior, see the Bazel Test Encyclopedia.

Filter by language

This command runs only js_test and go_test targets.

Well-known tags

You can add these to the tags attribute of a test to change the way Bazel runs it.
  • external - the test is intentionally non-hermetic, as it tests something aside from its declared inputs. Forces the test to be unconditionally executed, regardless of the value of --cache_test_results, so the result is not cached.
  • exclusive - the test is not isolated and can interact with other tests running at the same time. Exclusive tests are executed in serial fashion after all build activity and non-exclusive tests have been completed. They can’t be run remotely, either.
  • manual - essentially “skip” or “disabled”. It means a target wildcard pattern, like :all or //... won’t include this target. You can still run it by listing the target explicitly.
  • requires-network - declare that the test should run in a sandbox that allows network access.
  • flaky - run it up to three times when it fails. We’ll learn more about flakiness in a later lesson.
The Aspect CLI provides a handy way to find these: bazel help tags