Let's say I have class MyClass with methods x()
, y()
and z()
. Let's say x()
calls y()
, and y()
calls z()
.
So everytime I test x()
both y()
and z()
are called. In case of mocking the dependencies of MyClass I will have to mock the dependencies behavior inside x()
, y()
and z()
.
So if my tests for method x()
are testXWhen1()
, testXWhen2()
and testXWhen3()
I will have to repeat the expectations for my dependencies in each of the test methods. In the end, I have some code with the expectations for what happens inside y()
and z()
repeated for my three test methods. Any solution to avoid this?
One of my ideas was to try to test the actual x()
method, but mocking y()
and z()
. In that case my instance of MyClass
should be partly a mock and partly the real MyClass
. Is it possible?
Another solution was to be strict about expectations in x()
, but not about what happens in y()
and z()
... I think I can do that with @NonStrict
instead of @Mocked
, but it's not my favorite solution.