All test rules have some common attributes. Useful examples are size
and timeout
.
Size is an architectural hint. It implies a timeout, and the scheduler also reserves more RAM.
small
= unit test,short
timeoutmedium
= functional test,moderate
timeoutlarge
= integration test,long
timeoutenormous
= end-to-end test,eternal
timeout
You could specify an explicit timeout
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.
Size is useful for filtering. For example, you can use --test_size_filters=small
to ask Bazel to "just run the unit tests".
You can also filter with these flags:
--test_tag_filters
, for example, with=smoke
to run tests with a custom tag "smoke"--test_timeout_filters
, for example, with=-eternal
to skip running tests that take a long time. Note that by defaulteternal
is 15 minutes. See https://bazel.build/reference/test-encyclopedia#role-test-runner.--test_lang_filters
, for example with=js,go
to run just thejs_test
andgo_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