You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below example is taken from the GUnit examples directory. I uncommented the EXPECT_CALL() line.
TEST(GMock, ShouldFailDueToUninterestingGetCall) {
using namespace testing;
StrictGMock<interface> mock;
//EXPECT_CALL(mock, (get)())
// .WillOnce(Return(true)); // Comment to get an UNINTERESTING CALL
static_cast<interface&>(mock).get();
}
GMock gives this output:
Uninteresting mock function call - returning default value.
Function call: ()
Returns: NULL
get() have boolean return type, so returning NULL is wrong. If I instead mock the interface the usual GMock way using MOCK_CONST_METHOD0(get, bool());, I get the expected:
Uninteresting mock function call - returning default value.
Function call: get()
Returns: false
Replace bool with e.g. std::string in the GUnit case, and you will get a segmentation fault when a 0 is interpreted as a std::string. (GMock will correctly return an empty string.)
Maybe the right thing to do in GUnit would be to have the default method trigger an assert instead of this non-working call to the wrong version of GMock:s default actions? It's still nicer to use GUnit even if you always have to do EXPECT_CALL() to set default return values in the tests. What is your thoughts about this?
Are there any RTTI information available for method names, that would make it possible to print the name of the stubbed method invoked?
The text was updated successfully, but these errors were encountered:
Below example is taken from the GUnit examples directory. I uncommented the EXPECT_CALL() line.
GMock gives this output:
get() have boolean return type, so returning NULL is wrong. If I instead mock the interface the usual GMock way using MOCK_CONST_METHOD0(get, bool());, I get the expected:
Replace bool with e.g. std::string in the GUnit case, and you will get a segmentation fault when a 0 is interpreted as a std::string. (GMock will correctly return an empty string.)
Maybe the right thing to do in GUnit would be to have the default method trigger an assert instead of this non-working call to the wrong version of GMock:s default actions? It's still nicer to use GUnit even if you always have to do EXPECT_CALL() to set default return values in the tests. What is your thoughts about this?
Are there any RTTI information available for method names, that would make it possible to print the name of the stubbed method invoked?
The text was updated successfully, but these errors were encountered: