mpherg/googletest

Throwing an exception as default breaks call count expectation

Closed this issue · 3 comments

Example:

----
class MyMock {
public:
  MOCK_METHOD0(func, void());
};

TEST(MyTest, testMock) {
  MyMock mock;
  ON_CALL(mock, func()).WillByDefault(Throw(std::logic_error("error")));
  EXPECT_CALL(mock, func()).Times(0);
  try {
    mock.func();
  } catch (std::logic_error &e) {
  }
}
----

The test is green and passes. I expect it to fail, because the mock function is 
called once but I expect it not to be..

I assume in the gmock implementation, the call counter is incremented after the 
function returns and throwing an exception jumps over this piece of code.

Original issue reported on code.google.com by heinzis...@gmail.com on 18 Nov 2014 at 10:43

using gmock 1.7.0, gtest 1.7.0 on linux x64 (ubuntu 14.10)

Original comment by heinzis...@gmail.com on 18 Nov 2014 at 10:44

Sorry guys, I hit the wrong issue tracker. I refiled at the googlemock issue 
tracker here: 
https://code.google.com/p/googlemock/issues/detail?id=171&thanks=171&ts=14164832
07

You can close this issue here.

Original comment by heinzis...@gmail.com on 20 Nov 2014 at 11:34

Original comment by sbe...@google.com on 20 Nov 2014 at 3:33

  • Changed state: Invalid