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
-1
votes
1 answer

Factory Pattern w/ Gmock

I have a interface where I am using the factory pattern to create an instance of the object and store it in a unique_ptr. I also have a MockInterface which I would like to use in my tests to not call the actual production code. However when I run my…
-1
votes
1 answer

Using dependency injection and mocking it with gmock

I have implemented a Dependency Injection pattern in my code. I did that to be able to mock a service using gmock. The DI implementation works in production code, however, I am having trouble with my test setup. When using the EXPECT_CALL macro, I…
szumial
  • 63
  • 7
-1
votes
1 answer

How to simulate an EXPECT_CALL with gtest

In the code below I tried to explain my problem on a basic model. class A { public: A() {} virtual void foo() {} virtual ~A(){} //... }; class B : public A{ public: B(){} //... //does not contain the…
Ionut Alexandru
  • 680
  • 5
  • 17
-1
votes
1 answer

mock a function which has double pointer as argument

Mock a method which has raw double pointer, for example below class Helper has a method int run(int** a). I am trying to set expectations using SetArgPointee, but it is not working. giving compiler error can not convert int** const to int*. class…
-1
votes
1 answer

Why is original method mocked by GoogleMock still getting called?

I have been attempting to use GoogleMock to override a few specific methods in a underlying class, however I seem to be getting the base constructor, rather than the mocked object. Is there something obvious I am missing here? I have been following…
Aerophilic
  • 885
  • 2
  • 9
  • 22
-1
votes
1 answer

how to add implementation google mock setup in eclipse

Google mock example is created and built successfully in eclipse. I have followed same procedure given in link https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md C++ code is as followed; Student.hpp class Student { …
MAYUR KADLAG
  • 21
  • 1
  • 4
-1
votes
1 answer

Gtest: how to return different string value based on an increasing number every time in the expect_call?

const std::wstring tesName[3] = { L"Final", L"Partial", L"Best"}; My gtest will call a function GetName() hundreds of times. So I hope that the mocked function of GetName() can return like this: int i = 0; EXPECT_CALL(*my_mock,…
beasone
  • 1,073
  • 1
  • 14
  • 32
-1
votes
2 answers

How to test the sequence of function calls in C?

I'm using Gtest to perform unit testing to a C module. One of the requirements is to verify that a function called Supervision_Log() is called after executing several different functions. The C file includes the following: void MainFunction…
Mohamed Ameen
  • 65
  • 1
  • 8
-1
votes
1 answer

googlemock EXPECT_CALL with small behaviour variations

With the help of googlemock and googletest, I set up a test that checks that different mocked errors are correctly handled by the method under test. Basically my code looks like this: // setup mock object, and object under test // setup initial…
Ludwig Schulze
  • 2,155
  • 1
  • 17
  • 36
-1
votes
2 answers

How to test a string that contains a random value?

My mock class looks like this: struct StringEater { MOCK_CONST_METHOD1( ExecuteCommand, void( const char* ) ); }; and the string consist of part that doesn't change, and small part that I can not set in test. Something like this : Command 825…
BЈовић
  • 62,405
  • 41
  • 173
  • 273
-1
votes
1 answer

How to generate a mocked object that is created within the class being tested?

I have a testing class that instantiates a class that I wish to be mocked. Is this possible within the gmock framework? From what I read, it seems that the mocked object has to be created and passed to the object being tested and that is not what…
Adrian
  • 10,246
  • 4
  • 44
  • 110
-1
votes
1 answer

C++ - how to mock functions from different class, different headers?

I have one module which contain headers say h1, h2, h3 and cpp1 cpp2, cpp3. I am writing unit test function for function in cpp3 file say Foo();. The Foo() function calls Function F1() from cpp1 - definition and declaration in header h1 whose…
Statue
  • 1
  • 1
-1
votes
2 answers

Why isn't cmake locating gtest and gmock libs?

Here's a link to my project, just in case. So, here's my CMakeLists.txt file: cmake_minimum_required (VERSION 2.6) enable_testing() project (IeiuniumTela) set (IeiuniumTela_VERSION_MAJOR 1) set (IeiuniumTela_VERSION_MINOR 0) set…
bitcycle
  • 7,632
  • 16
  • 70
  • 121
-1
votes
3 answers

What did you do to solve gmock you mentioned (link enclosed)?

linking error when building Google test on mac (commandline) At the bottom, you wrote an edit about finding multiple gmock installations on the same computer messing up the include path for the compiler so it was hitting the old, 1.5 32 bit version…
Adam Miller
  • 1,756
  • 1
  • 25
  • 44
-2
votes
1 answer

google test: MOCK_METHODn (old style) - function with char** argument

I am using old version of google test, using MOCK_METHODn (old style) macros. I am trying to create a mock method for a virtual function with char** argument and receive compilation errors. Does anyone have example for mocking "**" arguments ?
Gidi
  • 7
  • 2
1 2 3
74
75