Mock private method in the same class that is being tested
问题 I have a Java class named, MyClass , that I want to test with JUnit. The public method, methodA , that I want to test calls a private method, methodB , in the same class to determine which conditional path to follow. My goal is to write JUnit tests for the different paths in methodA . Also, methodB calls a service, so I do not want it to actually be executed when I run the JUnit tests. What is the best way to mock methodB and control its return so that I can test different paths for 'methodA'