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);
        }
    
    }
  • 相关阅读:
    PHP数组函数
    sublime常用快捷键
    PHP中array_merge函数与array+array的区别
    【转】2017PHP程序员的进阶之路
    phpmyadmin上传sql文件大小限制问题解决方案
    二. python的os模块
    一. python的collections模块
    一. python进阶(文件的读写编码)
    七. python进阶(内置函数和高阶函数)
    六. python进阶(递归)
  • 原文地址:https://www.cnblogs.com/zjf-293916/p/7443939.html
Copyright © 2011-2022 走看看