我在测试用例中使用 Junit4 和 Mockito,在下面的代码dbprop.getProperty("config")
中抛出 aNullPointerException
因为 dbProp 为空。请帮我看看为什么它没有被嘲笑?
public abstract class BaseClass {
@Autowired
protected DBproperties dbprop;
}
public class SampleClass extends BaseClass {
@Autowired
private OrderService orderService;
valdiateOrder(String input) {
String config = dbprop.getProperty("config");
}
}
public class TestSampleClass {
@InjectMocks
SampleClass sampleClass;
@Mock
private OrderService orderService;
@Test
public void testValidateOrder() {
DBproperties dbprop = mock(DBproperties .class);
when(dbprop.getProperty("config")).thenReturn("xxxx");
assertNotNull(SampleClass.valdiateOrder("xxx"));
}
}