整合Junit

  1. 导入jar包

         基本 :4+1

         测试:spring-test...jar

1.让Junit通知spring加载配置文件

2.让spring容器自动进行注入

  1. 修改测试类

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations="classpath:applicationContext.xml")

在src下面要加locations

public class TestApp {

   

    @Autowired  //junit整合,不需要在spring xml配置扫描

    private AccountService accountService;

   

    @Test

    public void demo01(){

//       String xmlPath = "applicationContext.xml";

//       ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);

//       AccountService accountService =  (AccountService) applicationContext.getBean("accountService");

         accountService.transfer("jack", "rose", 1000);

    }

 

}