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

  • 相关阅读:
    ExtJS小技巧
    Oracle 表的行数、表占用空间大小,列的非空行数、列占用空间大小 查询
    NPM 私服
    IDEA 不编译java以外的文件
    SQL 引号中的问号在PrepareStatement 中不被看作是占位符
    Chrome 浏览器自动填表呈现淡黄色解决
    批量删除Maven 仓库未下载成功.lastupdate 的文件
    Oracle 11g 监听很慢,由于监听日志文件太大引起的问题(Windows 下)
    Hibernate 自动更新表出错 建表或添加列,提示标识符无效
    Hibernate 自动更新表出错 More than one table found in namespace
  • 原文地址:https://www.cnblogs.com/xifenglou/p/6185734.html
Copyright © 2011-2022 走看看