Consider the following simplified example (not a code which can be compiled). When running the TestA.test(), A.x() will call a real A.y() and not the mocked one. Is there any way to do that?
the class which should be tested:
public class A {
public void x() {
Object obj = y();
}
public Object y() {
return result;
}
}
the testing class:
public class testA {
@Test
void test() {
A a = spy(A.class);
when(a.y()).thenReturn("mocked");
a.x();
}
}
New contributor
Math.RandomDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2