Re: [googletest] Digest for googletestframework@googlegroups.com - 1 update in 1 topic

13 views
Skip to first unread message

David Wallace

unread,
Jul 4, 2019, 12:29:44 AM7/4/19
to Google C++ Testing Framework
If you use accessor methods to get or set the value of an instance variable, you can mock the accessors.  That's what I would normally do.  Or you could use an impure abstract class that defines the instance variable in question and let the concrete classes inherit it.  This can sometimes be useful when providing implementations of some specific methods in the abstract class.  I had to do this for one messaging class that had a variadic method that couldn't be mocked - I supplied an implementation in the abstract class that delegated to a non-variadic method, which then could be mocked.

Dave W.

On Tue, Jun 11, 2019 at 3:10 AM <googletes...@googlegroups.com> wrote:
"Thomas W." <thomas....@gmail.com>: Jun 10 01:54PM -0400

In "A Case for Mock Turtles" is a pretty simple example of defining an
interface for your dependency. But what if my class has data members of my
dependency? You can't declare data members of an abstract class.
 
I can make my class a template and resolve the data member on instantiation
of the class. So during tests I can instantiate with the mock class, and
during production I can instantiate with the real class. I can use the
"real" class as a default template parameter so it doesn't muck up my API.
 
But this seems to mean I have to use a lot of dynamic casting on my data
members if I want code completion. And all of this feels funny to me. Am
I going down the right path here?
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to googletestframe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages