Search code examples
javajunitjunit5

How to mock call private methods in Junit5?


Class A{
 public void testA(){
   // other codes
   priMethod();
   // other codes
 }

 private void priMethod(){
   // other codes
 }
}

I want to test testA method,The priMethod method is not the focus of the test and I want to skip it.Is there a method similar to dothing().when() ?

All I found were junit4 methods or ones that didn't work, but I wanted a junit5 solution since I couldn't change the junit version or the source code.


Solution

  • There is no way to mock private methods with Mockito

    Their wiki: https://github.com/mockito/mockito/wiki/Mockito-And-Private-Methods