使用@ContextConfiguration替换@SpringBootTest


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM