spring boot单元测试中出现response、request依赖注入错误

是因为UT时并不会启动http容器;需要在测试类首部增加注解:

@WebAppConfiguration

完整代码如下:

@WebAppConfiguration
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(HacksawApplication.class)
public class CargoDefIcdDAOTest {
    @Autowired
    private CargoDefIcdDAO cargoDefIcdDAO;
    
    @Test
    public void testInsert() throws IOException {
        //TODO
        
    }
}

猜你喜欢

转载自blog.csdn.net/lisulong1/article/details/81100651