googlemock Questions

3

Solved

I have a class Foo that uses class Bar. Bar is used only in Foo and Foo is managing Bar, therefore I use unique_ptr (not a reference, because I don't need Bar outside of Foo): using namespace std;...
Pilferage asked 9/11, 2016 at 13:21

2

I'm currently learning unit testing with google mock What is the usual use of virtual void SetUp() and virtual void TearDown() in the google mock? An example scenario with codes would be good.
Parietal asked 25/9, 2014 at 4:45

3

Solved

I'm trying to do some sleep inside .WillOnce before invoking FuncHelper. So I need something similar to the following: EXPECT_CALL(*_mock, Func(_,_,_)).Times(1) .WillOnce(DoAll(InvokeWithoutArgs(...
Plague asked 7/6, 2016 at 12:2

5

Solved

What will be the best way to write (google) test cases using a google mock object and expect the EXPECT_CALL() definitions being called from another thread controlled by the class in test? Simply c...
Ellipsoid asked 26/5, 2012 at 14:36

1

Not so much a question as a piece of knowledge sharing. According to the GoogleMock FAQ it is not possible to mock variadic functions since it is unknown how many arguments will be given to the fun...
Champac asked 2/12, 2014 at 15:16

5

Solved

How can I match value of an element in a union for an input argument e.g - if I mock a method with the following signatiure - struct SomeStruct { int data1; int data2; }; void SomeMethod...
Optimal asked 29/5, 2014 at 16:30

2

Solved

Google suggests delegating calls to a parent object when you need to invoke functionality of the real object, however this does not really create a partial (hybrid) mock. When invoking the real obj...
Iron asked 3/6, 2013 at 3:7

2

The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined. In particular, you must...
Dialectology asked 17/10, 2016 at 14:35

2

I have a class with several methods that depend on each other. Lets say foo(), bar() and baz(). When I test bar() I need to mock the behavior of foo(), when I test baz() I need to mock the behavio...
Thursby asked 28/8, 2014 at 19:30

3

Solved

If I call EXPECT_CALL twice on the same mock object in the same TEST_F . . . what happens? Are the expectations appended to the mock object or does the second call erase the effects of the first c...
Mozart asked 17/5, 2017 at 20:55

2

Solved

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 di...
Cheyney asked 29/5, 2017 at 19:25

0

It's tremendously helpful that there's a tool to generate mock versions of the client stubs. Testing the server side is causing me tons of headache at the moment. Enough headache where I feel like ...
Documentation asked 17/3, 2020 at 15:53

2

Solved

So I am trying to learn how to write unit Tests and i stumbled upon the problem, that I don't understand how to create mock objects. Here's my example: I have this class: class FooChild { public: ...
Davidadavidde asked 4/3, 2020 at 7:52

1

This is going to be a self-answered, FAQ-style question. See answer below. With Visual Studio 2017/2019 it is really easy to set up a new Google Test project and start writing tests (as long as you...
Ingeringersoll asked 2/3, 2020 at 9:42

2

I need to mock the following function: virtual void fun() noexcept = 0; Is it possible using gmock ? Gmock has the following macro:#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) but t...
Khano asked 15/7, 2019 at 21:23

2

Solved

Is there a macro in Google Mock to ensure compile time check of the signature of f() by appending the override keyword to the macro substitution: struct I { virtual void f() = 0; }; struct MockI...
Caesaria asked 19/2, 2020 at 10:38

4

I really like catch.hpp for testing (https://github.com/philsquared/Catch). I like its BDD style and its REQUIRE statements, its version of asserts. However, catch does not come with a mocking fram...
Unpen asked 27/5, 2015 at 14:46

2

I have not even begun testing and I am encountering some syntax issues with GMock's MOCK_METHOD macro even though I am following GMock's documentation properly. Could it be a compiler issue? I have...
Aloes asked 26/10, 2019 at 22:13

2

Solved

I'm mostly using ordered expectations with GoogleMock, so all EXPECT_CALLs were written inside the scope of a testing::InSequence object. Now I want to relax the ordering so I split the expectatio...
Studner asked 2/10, 2014 at 12:2

5

Solved

I have a factory that returns a smart pointer. Regardless of what smart pointer I use, I can't get Google Mock to mock the factory method. The mock object is the implementation of a pure abstract ...
Vide asked 30/9, 2011 at 21:54

2

Solved

My actual code (class name changed, some cut, as it is company confidential, but there is only one compiler error, so what I cut should not be affecting things) class Xyz { public: virtual void v...
Mime asked 16/9, 2015 at 14:59

2

Solved

The constructor of my class is A( ... std::function<bool(const std::string&, const std::string&)> aCallBack, ... ); I want to use EXPECT_CALL to test it. This callback is from a...
Vickyvico asked 1/3, 2017 at 0:18

3

Solved

In all the documentation about gmock I always find the mock object to be instantiated inside a test, like that: TEST(Bim, Bam) { MyMockClass myMockObj; EXPECT_CALL(MyMockObj, foo(_)); ... } S...
Sewer asked 28/8, 2015 at 8:29

3

Solved

I installed the Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn package into my VS 2017 application solution. This was accomplished by adding a new GoogleTest project to my solution via ...
Approximation asked 26/4, 2018 at 23:11

2

Solved

I am trying to use GMock (google mocking framework for c++) for the first time. I have the following class: class LocalCache { public: virtual time_t GetCurrentTime() = 0; virtual int AddEntry(c...
Eleen asked 12/9, 2015 at 1:40

© 2022 - 2024 — McMap. All rights reserved.