1

When I debug a normal application and assert() happens, I get the usual error window which allows me to stop execution and analyze call stack, local variables etc, which is very convenient:

assert

However when I am running a Google Test unit test, assertions never trigger the debugger. Instead I get this error text in cmd window:

Assertion failed: indexMap.size() == points.size(), file test.cpp, line 220
Press any key to continue . . .

Which is not nearly as helpful. I am pretty sure gtest messes up asserts somehow and prevents creation of the error window. Is there a way to have traditional assert behavior when I'm running unit tests?

Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
  • 2
    Are you sure this gtest unit was linked with debug version of CRT? – SergeyA Jan 18 '17 at 21:33
  • In the project settings it says: `Multi-threaded Debug DLL (/MDd)`. Just like the project where asserts work. Also in gtest CMake file I found this option: `-Dgtest_force_shared_crt=ON` – Aleksei Petrenko Jan 18 '17 at 21:42
  • @MuertoExcobito thank you, this is what I was looking for! There is a note about this in documentation, but I somehow missed it: https://github.com/google/googletest/blob/master/googletest/docs/V1_7_AdvancedGuide.md#turning-assertion-failures-into-break-points If there was also a way to make this a default behavior for CMake project (e.g. set define instead of command line option). But this is already great. – Aleksei Petrenko Jan 19 '17 at 08:53

0 Answers0