Spring与Junit测试整合

本文介绍如何通过Spring JUnit4ClassRunner结合@ContextConfiguration注解来指定Spring配置文件的位置,并实现对业务逻辑的单元测试。示例代码中演示了如何自动注入PersonService并调用savePerson()方法。

一、引入spring测试包:text包

二、@RunWith:指定spring对junit提供的一个运行器

  @ContextConfiguration:  locations指定spring配置文件位置

 1 @RunWith(SpringJUnit4ClassRunner.class)
 2 @ContextConfiguration(locations={"classpath:ApplicationContext.xml"})
 3 public class TestSpring1 {
 4     @Autowired
 5     private PersonService ps;
 6     @Test
 7     public void test1(){
 8         ps.savePerson();
 9     }
10 }

 

转载于:https://www.cnblogs.com/cat-fish6/p/8698499.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值