I am trying to see how test cases can drive interface design.
Now, if I have an interface with a method:
public interface UserService { User getNextUser(); }
and if UserServiceImpl is an implementation of UserService, then as per my understanding of mock objects, I should only mock the dependencies of the UserServiceImpl, like a UserRepository, because only then am I actually testing behaviour, i.e. does UserServiceImpl call UserRepository or not.
But then, if I must write a UserServiceTest, without creating a UserServiceImpl, then the only way I see is to create a mock of UserService, which doesn’t seem quite right.
Where am I going wrong with this?
I can’t say I completely understood what you’re trying to get at with your question, but the bottom line is that you can’t test a plain interface. If there’s no implementation, there’s nothing for a unit test to test.
The only way an interface could be “wrong” is if it doesn’t fulfill its design requirements, and that’s something only a human can tell.