Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ project with Bazel and GTest

Tags:

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)

like image 917
Picaud Vincent Avatar asked Aug 22 '17 10:08

Picaud Vincent


People also ask

Does Bazel use CMake?

Building CMake projectsIn BUILD. bazel , we instantiate a cmake rule which behaves similarly to a cc_library, which can then be used in a C++ rule (cc_binary in this case).

What is Gtest?

Google Test (also known as gtest) is a unit testing library for the C++ programming language, based on the xUnit architecture. The library is released under the BSD 3-clause license.


1 Answers

This is even easier now that googletest provides a BUILD file:

In WORKSPACE

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository(     name = "gtest",     remote = "https://github.com/google/googletest",     branch = "v1.10.x", ) 

In BUILD

cc_test (     name = "hello_test",     srcs = [         "hello_test.cc",     ],     deps = [         "@gtest//:gtest",         "@gtest//:gtest_main" # Only if hello_test.cc has no main()     ], ) 
like image 83
Phil Avatar answered Sep 22 '22 17:09

Phil