单元测试 java.lang.NullPointerException
idea可以右键-goto生成测试类,但是需要注意:
- 首先在calss上添加:
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = Application.class)
- 另外,不可以使用new方法来创建对象,因为对象没有交给Spring管理,对象里面的属性也就无法注入,为空了。
idea可以右键-goto生成测试类,但是需要注意:
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = Application.class)