I have a very basic understanding in mocking/stubbing.
When you create a stub in test code like:
test h = mock(test);
when(h.hello()).thenReturn(10);
and in source logic I have code like this:
test src = new test();
src.hello();
Now will stub get invoked since I've stubbed the hello method or Since the instance is different will it not get stubbed? Is there any way to stub all instances of the class?
A better way to write testable code is not to create cooperating classes by new operator in class code, but to pass cooperating classes as constructor arguments.
Then in test class: