My Scenario is as below
class SuperClass{
public void run(){
System.out.println(\"I am running in Super class\");
}
}
class ChildClass extends S
Ideally, you should "favor composition over inheritance".
If you don't have this option you could use doNothing which basically tells Mockito to do nothing when a method in a mock/spy object is called. This was also discussed here
Following code example should help
@Test
public void tst() {
ChildClass ch = Mockito.spy(new ChildClass());
Mockito.doNothing().when((SuperClass)ch).run();
ch.childRunner();
}
class SuperClass{
public void run(){
System.out.println("I am running in Super class");
}
}
class ChildClass extends SuperClass{
public void childRunner(){
System.out.println("Step 1");
run();
System.out.println("Last Step");
}
}
output:
Step 1
Last Step
In case you use super.run(); this won't work