Using google test in Bazel project
I'm using Bazel for my repository of computer vision samples. Currently, I work on image projection example and want to add tests. One of the best options for the unit test frameworks is the google test.
Bazel has a rich functionality to use external libraries in the project. The external library can be used a from local folder, http archive and git repository.
To be used as dependency in Bazel the library should be a bazel project. So erther it should already contain BUILD file, or we should provide the BUILD file in the dependent project.
Most of the examples of google test usage reference the second option: they propose to add "new_git_repository" the Bazel WORKSPACE and provide manually written BUILD file.
Obviously it is not the best solution since I would have to maintain the build rules for an external project.
But luckily in the release 1.8.1 the google test prject support Bazel build as well. And can be added to workspace as easy as
Tests themself can be written as usually, the smallest example:
WORKSPACE
BUILD
Bazel has a rich functionality to use external libraries in the project. The external library can be used a from local folder, http archive and git repository.
To be used as dependency in Bazel the library should be a bazel project. So erther it should already contain BUILD file, or we should provide the BUILD file in the dependent project.
Most of the examples of google test usage reference the second option: they propose to add "new_git_repository" the Bazel WORKSPACE and provide manually written BUILD file.
Obviously it is not the best solution since I would have to maintain the build rules for an external project.
But luckily in the release 1.8.1 the google test prject support Bazel build as well. And can be added to workspace as easy as
And later in your project it can be used like:# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# ...
git_repository(
name = "googletest",
remote = "https://github.com/google/googletest.git",
tag = "release-1.8.1"
)
# BUILD"gtest_main" in my example above is used to avoid implementing own main function for test.
cc_test(
name = "test_example",
srcs = [
"test_example.cpp"
],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main"
]
)
Tests themself can be written as usually, the smallest example:
#include <gmock/gmock.h>And now run:
TEST(TestExample, test)
{
ASSERT_TRUE(true);
}
$ bazel test ...The examples are available on github:
...
//gtest_example:test_example PASSED in 0.1s
Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 26 total actions
WORKSPACE
BUILD
King Casino Login | Full Analysis (2021) - Macmerit
ReplyDeleteLogin King Casino to make a deposit 메리트카지노 of between $1 and $2,000. The 파라오카지노 King casino gives access to new players using its own
Harrah’s pioneered the now trade standard Total Rewards participant monitoring system, first with a punchcard program launched in 1985, then with a digital program and magnetic cards in the Nineteen Nineties. Slots were easy to track, and stood on the very center of the program. The system grew even more refined underneath the auspices of former CEO Gary Loveman. Loveman arrived at Harrah’s fresh from teaching at Harvard Business School, and he introduced a methodical enterprise savvy to an trade that, in some ways, had spent a long time winging it. Slot machines are available on a first-come, first-served foundation and must be consistently 1xbet performed.
ReplyDelete