由于springboottest需要初始化上下文,每一次都要好长时间,可以使用其他方法替换它:

测试类如下:

@RunWith(SpringJUnit4ClassRunner.class)
// @WebAppConfiguration omitted on purpose
@ContextConfiguration(classes = WebConfig.class)
public class EmployeeTestWithoutMockMvc {
 
    @Autowired
    private EmployeeController employeeController;
 
    ...
}

 

WebConfig.java类:

@enableautoconfiguration
@enablejparepository
@entityscan("com.baeldung.domain")
@ComponentScan("com.baeldung.web")
public class WebConfig implements WebMvcConfigurer {
    ...
}

 

相关文章:

  • 2022-02-21
  • 2022-01-31
  • 2021-12-15
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-30
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
相关资源
相似解决方案