-2

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  
};

file2.hpp

struct B: virtual public testing::Test
{
    //function with MockB
};

file3.hpp

include file1 & file2
class C: public B, public A
{
    //call MockB -> fails here
};

If I only use the inheritance on "public B" or would put "public B" on 2nd position, the code works. However, I need both A & B to be tested in my class C and would get the same error for A (or B, depending the position).

How can I include both files and use their mocks?

P.S: both A&B have different names for MOCKS and would not influence one another. P.S 2: If situation is as above, I get: unknown file: Failure 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.

Actual function call count doesn't match EXPECT_CALL(...,.. )... Expected: to be called once Actual: never called - unsatisfied and active

  • 3
    Don't describe what your code might look like, just include full working (but [minimal](https://stackoverflow.com/help/minimal-reproducible-example)) example. There can be many reasons why it does not work for you (e.g. a typo), and gtest exception is quite self-explanatory, but hard to tell how you should set the default value if you don't show the code. – pptaszni May 03 '22 at 09:13

1 Answers1

0

The solution was to add EXPECT_CALLS in the 3rd file, not using the ones from file1 & file2