'How do we run a single test using Google bazel

For running all the tests under a target I use the command line command

bazel test //src/code_path:target_name

What should be additional parameters to run a test single_test from the above target?



Solution 1:[1]

On Googletest with the following setup:

TEST(TestSuite, test1)
TEST(TestSuite, test2)

you can isolate test1 using

bazel test --test_arg=--gtest_filter=TestSuite.test $TEST_TARGET_PATH

See --gtest_filter

Solution 2:[2]

You'll want to use --test_filter:

https://docs.bazel.build/versions/2.0.0/command-line-reference.html#flag--test_filter

The specific format of the value to the flag depends on the test runner.

Solution 3:[3]

--test_filter can be used:

For the following googletest test:

TEST(glog, log) {
  LOG(INFO) << "an INFO log message";
  VLOG(1) << "a vlog(1) message";
}

--test_filter=glog.log can be used to pick it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LeafyLi
Solution 2 ahumesky
Solution 3 Jingguo Yao