Is there a way to get EXPECT_THROW/EXPECT_NO_THROW to verbosely print error messages in the tests? I’m probably missing something, but when I’m working on code and I get an error in the test, I usually have to go unwrap the EXPECT_* statement and then re-run the code before I see the detailed error message that got thrown. If I leave the EXPECT_* statement there all that gets printed it something like “exception thrown when expected none” or something equivalent.
Not that I know of, but I’d like to hear back if you find a solution.
You can always write your own tests, which I’ve taken to doing more and more often. For example, to code up
EXPECT_THROW(foo(), T);
you can use
try {
foo();
FAIL(...);
} catch (const T& e) {
SUCCEED(...);
} catch (const std::exception& e) {
print some message about e
FAIL(...);
} catch (...) {
FAIL(...);
}
I don’t know of a good way either. I just usually run the code and see what exception is thrown. Google test will report the details of the exception if you don’t have a EXPECT_THROW
wrapping it.