(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);
}
}