Bazel
build system
test targets
error troubleshooting
software development

Bazel error No test targets were found, yet testing was requested

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

This Bazel error means your bazel test command resolved to zero actual test rules. Bazel is not saying tests failed; it is saying that, after expanding the target pattern and applying any filters, there was nothing of a test rule type left to run.

What Bazel Counts as a Test Target

Bazel only runs rules that are declared as test rules, such as:

  • 'cc_test'
  • 'java_test'
  • 'py_test'
  • 'go_test'
  • language-specific wrappers that ultimately produce test targets

A cc_binary or py_library is not a test target, even if it contains test-like code.

So if you run:

bash
bazel test //app/...

and there are no matching *_test rules under that package path, Bazel expands the pattern, finds no tests, and throws this error.

The Most Common Causes

The error usually comes from one of these situations:

  • the target pattern points at packages with no test rules
  • the named target exists but is not a test rule
  • a test_suite expands to nothing
  • tag or size filters exclude all discovered tests
  • the package path is wrong or outside the current workspace view

That is why the first task is always to inspect what Bazel thinks is available.

Use bazel query to See the Truth

A very effective debugging step is to ask Bazel to list test targets directly.

bash
bazel query 'kind(".*_test", //app/...)'

If this returns nothing, the error is expected: there are no test rules under that pattern.

If it returns test rules but bazel test still fails, then filters or target spelling are the next suspects.

Check the BUILD File

Here is a simple valid py_test example:

python
1py_test(
2    name = "math_test",
3    srcs = ["math_test.py"],
4    deps = [":math_lib"],
5)

If your BUILD file only contains something like this:

python
1py_library(
2    name = "math_lib",
3    srcs = ["math_lib.py"],
4)

then bazel test //path:math_lib will not work because math_lib is not a test rule.

Test Suites Can Also Be Empty

A test_suite is valid only if it actually expands to test targets.

python
1test_suite(
2    name = "all_tests",
3    tests = [":math_test"],
4)

If the tests list is empty, or points at rules that are not real tests, bazel test //path:all_tests can produce the same error.

This is especially common when someone refactors targets and forgets to update the suite.

Filters Can Accidentally Remove Everything

Sometimes Bazel does find test rules, but later filtering eliminates all of them.

Examples include:

  • '--test_tag_filters'
  • '--build_tag_filters'
  • '--test_size_filters'
  • platform or configuration constraints

A command such as:

bash
bazel test //app/... --test_tag_filters=integration

will fail with this message if none of the discovered tests carry the integration tag.

That makes the error look like a BUILD-file issue when it is really a filtering issue.

Package and Workspace Scope Matter

Bazel target patterns are workspace-relative. If the package path is wrong, Bazel may be looking in the wrong place entirely.

Useful checks:

bash
bazel query //app/...
bazel query //app:all

These help confirm that the package and targets you think exist are actually visible to Bazel under the current workspace.

A Practical Debugging Sequence

A reliable order of operations is:

  1. run bazel query 'kind(".*_test", //your/pattern/...)'
  2. open the relevant BUILD file
  3. confirm the target is a real test rule
  4. remove tag or size filters temporarily
  5. rerun bazel test with the simplest possible target pattern

This narrows the issue quickly without guesswork.

Common Pitfalls

A common mistake is running bazel test on a binary or library target and expecting Bazel to infer that it is a test.

Another issue is using a wide pattern such as //... and then filtering away everything with tags or sizes.

Developers also often forget that a test_suite can be syntactically present but semantically empty.

Finally, if bazel query returns no tests, do not keep tweaking flags. The BUILD graph itself is not exposing any runnable test targets for that pattern.

Summary

  • The error means Bazel found zero runnable test targets after expansion and filtering.
  • Verify actual test rules with bazel query 'kind(".*_test", ...)'.
  • Make sure the target is a test rule, not a library or binary.
  • Check test_suite contents and tag or size filters.
  • Start debugging with the simplest target pattern before adding filters.

Course illustration
Course illustration

All Rights Reserved.