我有A类,它依赖于B类.B类再次依赖C类.结构如下:
Class A(){
@Autowired
private B b;
public void someMethod(){
b.callAnotherMethodAndGetValue();
}
}
Class B(){
@Autowired
private C c;
public void callAnotherMethodAndGetValue(){
c.callAnother();
}
}
Class ATest(){
@Spy
private B b;
public void someMethod(){
// it goes into this method, and throws null pointer exception at
// c.callAnother(); as c is null.
b.callAnotherMethodAndGetValue();
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以让堆栈c.callAnother从Test Cases 流出来.没有做的时候b.callAnotherMethodAndGetValue();