class
WPApp : public WPModule
{
protected
:
HINSTANCE pinst; // previous instance handle
public
:
//...
BOOL first() { return pinst == NULL; }
//...
protected
:
virtual void run();
//...
};
namespace
ut_WpApp {
class Mock_WPApp : public WPApp
{
public:
Mock_WPApp()
{
//...
ON_CALL(*this, first())
.WillByDefault(Invoke(this, &WPApp::first));
ON_CALL(*this, run())
.WillByDefault(Invoke(this, &WPApp::run));
// error: cannot access protected membe }
//...
MOCK_METHOD0(first, BOOL ());
public: // must be public for mock
MOCK_METHOD0(run, void ());
};
}
}(sigh. the code formatting doesn't seem to have helped here.)
From what I see you can't specify the base class member function as a default action when it is not public. How would this be accomplished?
| class BaseTests : public testing::Test, public YourBaseClass {... If you think multiple inheritance is bad, writing untestable code is worse. |
class WPWin {}
class WPMainWin : public WPWin {}
class WPDialog : public WPWin {}
.etc.
The dilemma was testing the public api means the classes would create "live" windows, which I wanted to avoid; but that may not be possible. (Aside: the wxWdigets tests do create live windows). I though I would mock the base class dependencies (WPWin) to test the derived class (WPMainWin).
All without having to change the code. I am starting to think this isn't realistic. I think this needs a test double and that fells like a significant amount of work. And some original code change, which I wanted to avoid.
I'm starting to think best way forward is to define an interface class and use test doubles. I have to work out how that would look.
I really appreciate your feedback.
Reading the links now.
Why did I think this wouldn't be too onerous?
----- Original Message -----From: Keith RaySent: Wednesday, October 01, 2014 1:31 PMSubject: Re: [googlemock: 2170] Mocking Private or Protected Methods
----- Original Message -----From: Keith RaySent: Wednesday, October 01, 2014 2:41 PMSubject: Re: [googlemock: 2170] Mocking Private or Protected Methods
From: Keith RaySent: Wednesday, October 01, 2014 3:34 PMSubject: Re: [googlemock: 2170] Mocking Private or Protected Methods