public class PotentialStubbingProblem extends MockitoException
org.mockito.exceptions.misusing.PotentialStubbingProblemexception is thrown when a mock method is stubbed with argument X in test but then invoked with argument Y in code. Example:
The stubbing argument mismatch typically happens in following use cases:
//test method: given(mock.getSomething(100)).willReturn(something); //code under test: Something something = mock.getSomething(50); // <-- stubbing argument mismatch
What to do if you fall into use case 3? You have 2 options:
Mockito.doReturn(Object)family of methods for stubbing. Good looking stubbing via
Mockito.when(Object)has its drawbacks: the framework cannot distinguish between actual invocation on mock and the stubbing attempt in the test. Hence the need to use
Mockito.doReturn(Object)for certain edge cases.
Strictness.STRICT_STUBSfor that test. You will lose stubbing strictness but at least you can complete the test.
We are very eager to hear feedback about "strict stubbing" feature, let us know by commenting on GitHub issue 769. Strict stubbing is an attempt to improve testability and productivity with Mocktio. Tell us what you think!
|Constructor and Description|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public PotentialStubbingProblem(String message)