I have the following class which I try to test:
public class ClassA extends ClassB {
...
public String methodToBeTested(){
methodA1();
methodB();
return something;
}
...
}
The methodB
is parent class's method. I want to ignore this method or just stub it. I'm trying the following more and less:
public class TestClassA{
@Mock
ClassB instanceB;
public String testTheMethodToBeTested{
doNothing().when(instanceB).methodB();
ClassA instanceA = new ClassA();
String result = instanceA.methodToBeTested();
String expected = "foo"
assertTrue(result.equals(expected));
}
...
}
However I see that methodB
still is being executed. However in ClassA
if I declare a classB variable and it's setter; and instead of methodB()
write classB.methodB()
my tests executes. But I am asked to not change the code being tested. Is there any way to test ClassA
?
Aucun commentaire:
Enregistrer un commentaire