I’m just getting into Test Driven Development with mock objects. I can do it the long way with UnitTest++, but now I want to try to minimize typing, and I’m trying to use AMOP mock framework to do the mocking.
AMOP states:
The main differences between AMOP and other mock object library is that,
users DO NOT need to implement the
interface of the object which to
mock…
However, I can’t figure this out. The basic usage page still shows a IInterface class. Anyone able to do it without using an interface class?
For what I’ve seen in the documentation, it actually doesn’t need the mock object to implement any interface. The mocking object is constructed based on the original object’s interface, but not by inheritance, but as a parameter of the class:
No inheritance here, and TMockObject doesn’t get tied to any interface by inheritance. Then, adding mock methods to be implemented by the mock object:
Again, the object
mockdoes not actually inherit the interface. It may redefine the conversion operator toIInterface*(it will return an internalIInterfaceobject).I don’t see many advantages in not inheriting the interface, but anyway. I would have preferred some template as member function of
TMockObjectto give more meaning to that ugly cast (not tested, just an idea):so you could write something like:
but still…