由于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 { ...}
