zoukankan      html  css  js  c++  java
  • spring-test测试demo

    如果是maven项目,pom中增加如下依赖:

    <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>3.1.1.RELEASE</version>
    </dependency>

    import org.apache.log4j.Logger;
    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.alibaba.fastjson.JSON;
    import com.joey.model.InfoCfg;
    import com.joey.model.UrUser;
    import com.joey.service.InfoCfgServiceI;
    import com.joey.service.UrUserServiceI;

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = { "classpath:spring.xml", "classpath:spring-mybatis.xml" })
    public class TestMybatis {

        //public ApplicationContext ac;
        private static final Logger logger = Logger.getLogger(TestMybatis.class);

        private InfoCfgServiceI infoService;
        private UrUserServiceI uruserService;

    /*    @Before
        public void before(){
            ac=new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"});
            uruserService = (UrUserServiceI)ac.getBean("uruserService");
            infoService = (InfoCfgServiceI)ac.getBean("infoService");

        }*/
        
        @Test
        public void test1() {
            InfoCfg u = infoService.get****(2985l); //相关业务方法
            logger.info(JSON.toJSONStringWithDateFormat(u, "yyyy-MM-dd HH:mm:ss"));
        }
        
        @Test
        public void testUser() {
            UrUser u = uruserService.******(285l);  //相关业务方法
            //logger.info(JSON.toJSONStringWithDateFormat(u, "yyyy-MM-dd HH:mm:ss"));
            logger.info(u.getUserId()+",,,,"+u.getCompany());
        }

        public InfoCfgServiceI getInfoService() {
            return infoService;
        }

        @Autowired
        public void setInfoService(InfoCfgServiceI infoService) {
            this.infoService = infoService;
        }

        public UrUserServiceI getUruserService() {
            return uruserService;
        }

        @Autowired
        public void setUruserService(UrUserServiceI uruserService) {
            this.uruserService = uruserService;
        }
    }

  • 相关阅读:
    websocket协议
    vue组件之间的传值
    vue中非父子组件的传值bus的使用
    $.proxy的使用
    弹性盒模型display:flex
    箭头函数与普通函数的区别
    粘贴到Excel的图片总是有些轻微变形
    centos rhel 中文输入法的安装
    vi ,默认为 .asm .inc 采用nasm的语法高亮
    how-to-convert-ppk-key-to-openssh-key-under-linux
  • 原文地址:https://www.cnblogs.com/xifenglou/p/6185734.html
Copyright © 2011-2022 走看看