org.mockito.exceptions.misusing
public class PotentialStubbingProblem extends MockitoException
org.mockito.exceptions.misusing.PotentialStubbingProblem
exception is thrown when a mock method is stubbed with argument X in test but then invoked with argument Y in code.
Example:
//test method:
given(mock.getSomething(100)).willReturn(something);
//code under test:
Something something = mock.getSomething(50); // <-- stubbing argument mismatch
The stubbing argument mismatch typically happens in following use cases:
What to do if you fall into use case 3? You have 2 options:
BDDMockito.willReturn(Object)
or 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 BDDMockito.willReturn(Object)
or Mockito.doReturn(Object)
for certain edge cases.
MockitoRule.strictness(Strictness)
with Strictness.STRICT_STUBS
for 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 |
---|
PotentialStubbingProblem(String message) |
getUnfilteredStackTrace
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public PotentialStubbingProblem(String message)