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!