I'm using Google Test and Google Mock frameworks for a project's unit tests. I have various unit tests projects and want to automate my build so to run all of them.
I was expecting the unit tests executable to return 0 on success and 1 (or any other value) on any test failure, but I'm getting 1 when all tests passed. I'm getting some GMOCK warnings but couldn't find any documentation about warnings affecting return value.
I tried running the tests filtering to run just one test case where no GMOCK warnings are triggered and still get 1 as return value.
I had a couple of DISABLED test cases, so I commented them out. Still getting 1 as return value.
According to documentation and code comments for RUN_ALL_TESTS
macro, the return value should be 0.
I can't think of anything else causing return value 1. Am I missing anything?
If you look at the definition of the RUN_ALL_TESTS()
macro from gtest.h there's clearly stated that 0 is returned on no failures:
// Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise.
//
// RUN_ALL_TESTS() should be invoked after the command line has been
// parsed by InitGoogleTest().
#define RUN_ALL_TESTS()\
(::testing::UnitTest::GetInstance()->Run())
Appearantly even warnings (from gmock) may result in a return value of 1. Try what happens if you get rid of the gmock warnings (e.g. using s.th. like NiceMock<> to wrap your mock class instance).