spring测试起步

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangjun5159/article/details/79295171

开始一个测试

类上只要添加这3个注解,就可以开始测试了。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(“classpath:spring-context.xml”)
@WebAppConfiguration

注解的作用

@ContextConfiguration用来加载根applicationcontext
@WebAppConfiguration,用来创造伪造的servletcontext,request、response,比较专业的名字叫MockServletContext

事务

默认事务都回滚,如果提交可以添加@Commit,@Commit用来替代@RollBack,目前推荐使用@Commit

猜你喜欢

转载自blog.csdn.net/wangjun5159/article/details/79295171
今日推荐