Googletest: How to include all my tests in one executable?

I am using Google test environment for C ++. Following the documentation and examples, I get a separate executable for each test ".cc" file that I create. Is there a way to create a single executable that will call all my unit tests?

I would like to put my project in a CI tool that reports the status of the test, so I would like to have one XML input file instead of many.

The meat of my make file looks like this:

class1_unittest.o : $(USER_TEST_DIR)/class1_unittest.cc $(USER_DIR)/class1.h $(GTEST_HEADERS)
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_TEST_DIR)/class1_unittest.cc

class1_unittest : class1.o day.o class1_unittest.o gtest_main.a
     $(CXX) $(CPPFLAGS) $(CXXFLAGS) -pthread $^ -o $(PROJECT_BIN)/$@

class2_unittest.o : $(USER_TEST_DIR)/class2_unittest.cc $(USER_DIR)/class2.h $(GTEST_HEADERS)
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_TEST_DIR)/class2_unittest.cc

class2_unittest : class2.o day.o class2_unittest.o gtest_main.a
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -pthread $^ -o $(PROJECT_BIN)/$@
+3
source share
1 answer

Makefile main() , main.cc, .

docs, TEST() Google Test. , main.cc, :

#include "gtest/gtest.h"
int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
+2

All Articles