项目场景:
单元测试
问题描述
单元测试的时候,加了自动注入注解以后,还是显示报错mapper为null
java.lang.NullPointerException: Cannot invoke "com.zygg.parkingsystem.dao.UserMapper.insert(Object)" because "this.userMapper" is null
原因分析:
未在测试类上面加@RunWith和@SpringBootTest注解
解决方案:
@RunWith(SpringRunner.class)
@SpringBootTest(classes= ParkingSystemApplication.class)
public class UserMapperTest {
@Autowired
private UserMapper userMapper;
@Test
public void testInsert(){