我看着在論壇,但找不到爲什麼會發生這種事方法的Mockito返回null
我
public class AImpl implements A{
@Autowired
B bImpl;
protected void doSomething(){
String s = "test";
String d = b.permuteString(s);
System.out.println(s.substring(1));
}
}
public class BImpl implements B{
public String permuateString(s){
return s;
}
}
在測試中我有:
@InjectMocks
AImpl aImpl;
@Mock
BImpl bImpl;
@Test
public void testCode(){
testCode(){
aImpl.doSomething();
}
}
的方法permuateString
從BImpl
總是返回null。我需要知道permuteString()的結果才能繼續執行doSomething。所以它不能爲空
爲什麼?
我使用Mockito
什麼值是B B;分配? – LanternMike
如果未分配'B b',b.permuateString(s)'應拋出'NullPointerException'。 –
對不起,我的意思是b是bImpl,它是自動裝配的。我在調試testng時發現它不爲空 – Dejell