600 Actions

Is it possible to inject a dependency of my mock into a class that belongs in a different package?Have you considered carefully the difference between integration tests vs pure unit tests? Seems like if you are allowing calls from A to B to C to D to the database, then you are trying to perform an integration test, in which case you should not be trying to mock out the database connection, but rather have a rollback-test instead. If you really do want to pure unit test, then only test directly what your Class A method does and its interaction with direct collaborators (i.e. class B only). You are free to either mock or not mock the collaborator.

Not Call dependency in MockitoSecondly, if you are testing class A, then you should almost never want to mock out any functionality within that class. That is why it is called "unit testing". Your unit is the class, and you access it through its exposed methods -- but you access the unit as it functions as a whole.

Oct14

comment

Not Call dependency in MockitoFirst of all, you really need to turn this into a question. I assume you are asking "why do I see callmethod2 being called when I mocked it?".