I want to create a Bazel C++ project with gtest for unit tests.
What is the minimal setup?
(I only have Bazel installed on my computer and I am running under Linux)
I want to create a Bazel C++ project with gtest for unit tests.
What is the minimal setup?
(I only have Bazel installed on my computer and I am running under Linux)
The project structure is:
Files related to Bazel+GTest
There you download gtest from github:
You define a gmock BUILD file defined below:
This BUILD file is in charge of compiling gtest/gmock:
This build file generate the tests:
The test/message_test.cpp file is defined by:
And that is all! The other files are defined as usual:
Files for the supporting example
Creates the libMyLib.so and libMyLib.a libraries.
with a basic message.hpp
and message.cpp
example.
Creates the hello executable.
which is:
Usage:
This will also download gtest from its github repo and compile it
You can run it with:
That was the main point of this note:
You should get something like:
Reproduce the results
For your ease I have created a github repo containing this example. I hope it works out of the box.
This is even easier now that googletest provides a BUILD file:
In WORKSPACE
In BUILD