[Solved] org.mockito.exceptions.misusing.PotentialStubbingProblem

PotentialStubbingProblem is a RuntimeException and subclass of MockitoException. Mockito framework throws this exception when “stubbing arguments mismatch“.

Strict stubbing is a new opt-in feature for JUnit Rule and JUnit Runner to detect potential stubbing problems org.mockito.exceptions.misusing.PotentialStubbingProblem exception is thrown when mocked method is stubbed with some argument in test but then invoked with different argument in code.

This exception can occurred by many reasons:

  1. Mistake or typo in the test code, the argument(s) used when declaring stubbing’s is unintentionally different.
  2. Mistake or typo in the code under test, the argument(s) used in the code under test is unintentionally different.
  3. Intentional use of stubbed method with different argument, either in the test (more stubbing) or in code under test.


  • PotentialStubbingProblem(String message) : Will throw exception with message.


 //test method:

 //code under test:
// stubbing argument mismatch
 Something something = mock.getSomething(100);


public class TestExample {
     public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);

     @Test public void exampleTest() {
         //Change the strictness level only for this test method:

         //remaining test code
         //Will work
         Something something = mock.getSomething(100);




Know More

To know more about Junit, Mockito and exception solutions follow below links: