I am calling a googletest in the post-build step of a C++ project in VS 2012.
Naturally, when any of the tests fail, the googletest command returns failure (-1), and the entire project is marked as a failure by Visual Studio.
I do not want that. I want the googletest to be run, and I want to see the results in the output, but I do not want to fail the project if not all tests pass.
Is there any flag that I can pass into googletest so that it always returns success (zero)?
The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).
gtest-parallel is a script that executes Google Test binaries in parallel, providing good speedup for single-threaded tests (on multi-core machines) and tests that do not run at 100% CPU (on single- or multi-core machines).
The ::testing::InitGoogleTest method does what the name suggests—it initializes the framework and must be called before RUN_ALL_TESTS . RUN_ALL_TESTS must be called only once in the code because multiple calls to it conflict with some of the advanced features of the framework and, therefore, are not supported.
Death Tests are test assertions to put in unit test code, just like ASSERT_EQ , that check that the program exists or crashes in a certain manner given some inputs. So in the program code we still use assert() or other traditional methods to close/crash the application.
Yes, you can make the test return 0
if you write your own main
function.
I imagine you're linking your test executable with the special gtest_main
library which is a very basic helper to allow you to avoid having to write your own main
function.
It's pretty much just doing:
int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The RUN_ALL_TESTS
macro is the culprit which is returning -1
, so all you need to do is stop linking with gtest_main
and write your own main
more like:
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
For more info on this topic, see the GoogleTest docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With