Questions tagged [googlemock]

Designed with C++'s specifics in mind, Google C++ Mocking Framework (or Google Mock for short) is a library for writing and using C++ mock classes.

Inspired by jMock, EasyMock, and Hamcrest, and designed with C++'s specifics in mind, Google C++ Mocking Framework (or Google Mock for short) is a library for writing and using C++ mock classes.

Google Mock:

  • lets you create mock classes trivially using simple macros,
  • supports a rich set of matchers and actions,
  • handles unordered, partially ordered, or completely ordered expectations,
  • is extensible by users, and
  • works on Linux, Mac, OS X, Windows, Windows Mobile, minGW, and Symbian.
1120 questions
10
votes
1 answer

Workaround for gmock to support rvalue reference

gmock does not support rvalue reference as parameter of mocked function (issue report). For example the following code will not compile: MOCK_METHOD1(foo,void(std::string&&)); I can't find information on when gmock will add support to this.
Edmund
  • 697
  • 6
  • 17
9
votes
2 answers

Google Mock: "no appropriate default constructor available"?

Using Visual Studio 2010 C++ with googlemock. I'm trying to use a mock I created and I'm getting the compiler error on the line: EmployeeFake employeeStub; The error is: 1>c:\someclasstests.cpp(22): error C2512: 'MyNamespace::EmployeeFake' : no…
User
  • 62,498
  • 72
  • 186
  • 247
9
votes
2 answers

Google Mock: multiple expectations on same function with different parameters

Consider the case where a certain mocked function is expected to be called several times, each time with a different value in a certain parameter. I would like to validate that the function was indeed called once and only once per value in a certain…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
9
votes
4 answers

Google Mock: Mocked overloaded functions create warning C4373

I'm mocking a C++ class which has 2 overloaded functions using Google Mock and VS2010: #include "stdafx.h" #include "gmock/gmock.h" #include "A.h" class MockA : public A { public: // ... MOCK_METHOD3(myFunc, void(const int id, const int…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
9
votes
1 answer

Unresolved external symbol error with Google Mock and Vcpkg

I have created a simple C++ test project with one mocking class: #include #include class TestMock { public: MOCK_CONST_METHOD0(Method1, void()); }; TEST(Test, Test1) { TestMock mock; } int main(int argc,…
Hein Gustavsen
  • 395
  • 3
  • 15
9
votes
2 answers

google mock - how to say "function must be called ONCE with a certain parameter but ok to be called many times with different parameters"?

I need to detect that a given function has been called exactly ONCE with a certain set of arguments. EXPECT_CALL(Mock_Obj, func("abc")).Times(1) but it's ok for that function to be called with different arguments any number of times. How do I…
Bob
  • 4,576
  • 7
  • 39
  • 107
9
votes
2 answers

How to use gmock to mock up a std::function?

The constructor of my class is A( ... std::function aCallBack, ... ); I want to use EXPECT_CALL to test it. This callback is from another class B. I created a Mock like class BMock : public B { …
zeejan
  • 265
  • 1
  • 4
  • 10
9
votes
1 answer

Using google test to check callbacks

I have a class Foo that stores a pointer to a callback. The callback could be invoked with a method InvokeCallback(). void* SomeCallback(void* a) { return (void*)(*(int*)a + 10); } class Foo { public: typedef void*…
Konstantin
  • 2,937
  • 10
  • 41
  • 58
9
votes
1 answer

What is the difference of saveArg and saveArgPointee in gmock?

I am studying in the gmock. Now Im trying to mock the class named "task", like this: class MockTask : public Task { public: MOCK_METHOD3(Execute, bool(std::set &setDeviceIDs, int timeout, PACKET_DATA *Data)); }; And I want to save…
XHLin
  • 301
  • 1
  • 3
  • 13
9
votes
1 answer

Using Google Mocks, how to give a mock implementation without caring about / setting any expectation of invocation

I have an interface class say: class MyInterface { public: virtual int doThing(int x, int y, int z) = 0; }; I want to write a mock implementation for use in my tests. E.g.Traditionally, without using Google Mocks, I would write say: class…
nappyfalcon
  • 909
  • 1
  • 10
  • 17
9
votes
1 answer

How can I mock a method with a return type of unique_ptr in Google Mock?

I have read Can Google Mock a method with a smart pointer return type? but it did not really give much of an answer. I have a factory that returns unique_ptr instances. Returning unique_ptr is a requirement that cannot change without really good…
dawsonc623
  • 1,841
  • 2
  • 16
  • 26
9
votes
1 answer

Matching arguments of custom type in googlemock

I have a problem matching a function argument to a specific object using google mock. Consider the following code: class Foo { public: struct Bar { int foobar; } void myMethod(const Bar& bar); } Now I have some testing…
anhoppe
  • 4,287
  • 3
  • 46
  • 58
9
votes
3 answers

SEH exception when using googlemock

I am starting to use googlemock with googletest but am getting an SEH exception that I can't figure out. The error message is: unknown file: error: SEH exception with code 0xc0000005 thrown in the test body. I have read some similar questions on SO…
stevejpurves
  • 923
  • 1
  • 7
  • 12
9
votes
3 answers

Compile error when I #include "gmock/gmock.h"

I'm attempting to integrate googlemock into my tests. I had already successfully built and run tests on googletest, and now am trying to incrementally add the gmock functionality into the tests as well, but I've hit a compile error that I utterly…
whazzmaster
  • 566
  • 1
  • 4
  • 16
8
votes
1 answer

GMOCK EXPECT_CALL on unique_ptr

One of the benefits of dependency injection is ease of testing, as mocked classes can be injected. Clazz takes raw pointer for that purpose and moves it to unique pointer, to signal that it owns InjectedObj object: Clazz::Clazz(InjectedObj…
Mateusz Wojtczak
  • 1,621
  • 1
  • 12
  • 28