The mock function has no default action set, and its return type has no default value set
Asked Answered
Z

0

8

I'm doing a google mock test for my code and I get this error when I run the test. Specifically, when I comment out the default constructor of my mock then the error vanishes. I want to understand why this happens.

Here is an example of my code:

In my mock.hpp:

struct MockWidget
{
  MockWidget();
  ~MockWidget();
};
typedef ::testing::NiceMock<MockWidget> NiceMockWidget;

In my mock.cpp:

MockWidget *pMockWidget = nullptr;
MockWidget::MockWidget()
{
    poMockWidget = this;
}

MockWidget::~MockWidget()
{
    poMockWidget = nullptr;
}

In my test.cpp:

class WidgetTest : public::testing::Test
{
    protected:
        //some code here 
    public:
        NiceMockWidget mockWidget;
}

Test(WidgetTest, Test01)
{
    //some code here
}

Now even if my Test01 test does not use mockWidget I get the error stated in the title. If I remove the constructor definition and declaration the error is gone. Any help? Thanks!

Zora answered 4/10, 2017 at 7:10 Comment(2)
Inside the protected block is the SetUp() and TearDown() functionsZora
Have you used an EXPECT_CALL(mockWidget,something()).WillOnce(testing::Return(something)) ?Outdare

© 2022 - 2024 — McMap. All rights reserved.