Reputation: 4523
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)?
Upvotes: 5
Views: 3975
Reputation: 78330
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.
Upvotes: 5