zoukankan      html  css  js  c++  java
  • 转账_整合Junit

    l  导入jar包

           基本 :4+1

           测试:spring-test...jar

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

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

    首先,我们需要修改测试类,在原有的基础上,让其不需要在类中使用spring容器

    我们在上篇博文中将测试类修改为如下代码,其他类以及.xml文件均不做修改,也可以实现转账功能

    package com.itheima;
    
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import com.itheima.service.impl.AccountService;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations="classpath:applicationContext.xml")
    public class TestApp {
        @Autowired  //与junit整合,不需要在spring xml配置扫描
        private AccountService accountService;
        @Test
        public void demo01(){
    //        //获得容器
    //        String xmlPath = "applicationContext.xml";
    //        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
    //        //获得容器内容,不需要自己new,都是从spring中获得,applicationContext.getBean("accountService")指的是id
    //        AccountService accountService =  (AccountService) applicationContext.getBean("accountService");
            accountService.transfer("jack", "rose", 1000);
        }
    
    }
  • 相关阅读:
    jquery加入购物车飞入的效果
    jQuery点击div其他地方隐藏div
    移动对meta的定义
    ZOJ
    博弈dp入门 POJ
    ZOJ 2967计算几何+单调栈
    牛客训练41D最小相似度bfs
    球的体积并
    二进制上的数位dpPOJ 3252
    数位dp入门 HDU 2089 HDU 3555
  • 原文地址:https://www.cnblogs.com/zjf-293916/p/7443939.html
Copyright © 2011-2022 走看看