您的位置:首页 > 编程语言 > Java开发

spring与JUnit整合

2016-10-15 14:19 330 查看
(1)导入JUnit4的jar包,和spring基础包+spring-test包

(2)测试样例

import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class SpringDemo1 {

//测试业务层类
@Resource(name="accountService")
private AccountService accountService;

//测试DAO类
@Resource(name="accountDao")
private AccountDao accountDao;

@Test
public void demo1(){
accountService.transfer("aaa", "bbb", 200d);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: