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

Testing the contents in std::unordered_map without worrying about the order

I am looking to check whether the strings outputted match against the expected one without worrying about the order in which they are printed. Here, std::unordered_map stores the A objects as values and since it's not ordered, it becomes tricky…
xyf
  • 664
  • 1
  • 6
  • 16
-2
votes
1 answer

Mocking a method with std::vector of windef RECT as argument using GMock version 1.21

I am having trouble in mocking the following method. I have this code: // contents of XRECT.h using VRECT = std::vector; class XRECT { public: virtual bool DisplayRect(VRECT rects) = 0; } class CXRECT : public XRECT { public: …
kishoredbn
  • 2,007
  • 4
  • 28
  • 47
-2
votes
1 answer

gMock Visual Studio test crashes when using EXPECT_CALL

When running my test from the Test Explorer in Visual Studio 2022 [17.2.0], testhost.exe crashes when my unit test has a gMock EXPECT_CALL call in it. What am I doing wrong? Minimal code: #include #include…
Talset
  • 61
  • 2
  • 18
-2
votes
1 answer

C++ google test, mocks not called on inherited classes

As said in the title, I try to test my code using google test, but I get some issue on inheritance of mocks. I will further present the structure of my code: file1.hpp struct A: virtual public testing::Test { //function with MocksA …
-2
votes
1 answer

Save a char* parameter intro a string

Please help me with this question.. I'm beginner with gtest. I have a mocked function DoSomething(const char* par0, const char* par2) I want to save its second argument into std::string `savedPar_`; EXPECT_CALL(mockd_, DoSomething(_, _,)) …
John Kan
  • 25
  • 6
-2
votes
1 answer

Avoid in tests too much mock with static variable in source code

I try to run several tests in once (using GoogleTest) on source code I wrote containing static const variable initialized through network (which is "mocked" to imitate real behavior). Example static const std::string myStr{getNameFromNetwork()}; The…
Meugiwara
  • 599
  • 1
  • 7
  • 13
-2
votes
1 answer

I got an error while running my gtest and I don't know anything about it

I got the issue MockInterfaceTest.MockTest unknown file: error: C++ exception with description " The mock function has no default action set, and its return type has no default value set." thrown in the test body. Can anyone explain why this…
-2
votes
1 answer

When can a test in Google Test Framework fail?

I have a test for Google Test Framework that is failing without any further explanation, meaning that the test suite is not crashing but is correcly ending its execution printing: [ PASSED ] 0 tests. [ FAILED ] 1 test, listed below: with the…
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
-3
votes
1 answer

Operator overloaded new when void * nullptr makes the program to crash

I have a code to test via Google Mock but facing a peculiar issue. There is a class that overloads new operator, the overloaded methods has a logic to return (void) nullptr* say when creating more that 2 objects. Now in the main code we have a for…
Programmer
  • 8,303
  • 23
  • 78
  • 162
-3
votes
2 answers

Segmentation fault when calling expectation on a pointer return function

Segmentation fault when calling expectation on a function that return a pointer. data.h struct Data { int age; Data(); ~Data(){} }; master.h class Master { private: Data *m_data; public: Data* getData() const…
dochoex
  • 191
  • 1
  • 3
  • 11
1 2 3
74
75