On Jun 23, 9:45 am, vlad <
megav...@gmail.com> wrote:
> Thank you for the link, similarly named fellow human being. Also you,
> Jared Wein.
>
> I hope this turn out to be of help, but I don't think that's what I
> need.
>
> Consider this common use case I have:
>
> I have 3 classes, A, B, and C which make use of external engine's
> GraphicNode class.
> Class C makes use of it directly, while class A and B indirectly, by
> way of C.
In the case, a sensible thing to do would be to test class C by
mocking GraphicNode,
but test A and B by mocking C. If A and B are using C, not
GraphicNode, then they need
to know about a mock GraphicNode even less than a real one.
Generally, mock object testing is much easier if you mock only a
class' immediate neighbours.
>
> Lets further assume the calls go something like:
> a.foo() -> c.bar() -> node.attach(a)
> b.bez() -> c.bar() -> node.attach(b)
>
> I want to test the A and B classes:
>
> TEST(Graphics, Test)
> {
> ...
> // Here, GraphicNode needs to be set up a certain way.
> ASSERT_TRUE(a.foo());
>
> // Here, GraphicNode needs to be set up a different way.
> ASSERT_TRUE(b.foo());
>
> // We never use class C directly, which is the one talking to
> GraphicNode.
> ...
So this is really three tests, not two: one test for class C, testing
that c.bar() calls
node.attach() in the way that you want, and one test each for A and B
testing that foo()
calls c.bar() in the way that you want. The latter tests don't need to
test that node is
handled correctly, because you've already tested that in the first
test.