如果是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;
    }
}

spring-test测试demo的更多相关文章

  1. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  2. Spring Security OAuth2 Demo —— 隐式授权模式(Implicit)

    本文可以转载,但请注明出处https://www.cnblogs.com/hellxz/p/oauth2_impilit_pattern.html 写在前面 在文章OAuth 2.0 概念及授权流程梳 ...

  3. mock api测试demo

    前言 本测试demo基于Spring框架测试,这几个月也是刚刚接触Spring的项目.如果不对的地方请多谅解. 正文 1.创建测试类,添加注解 @RunWith(SpringRunner.class) ...

  4. 学习写简单Spring源码demo

    最近在研究怎么实现简单的Spring的源码,通过注解的方式来实现对bean的加载管理. 首先先来看下我的工程结构: (1)spring-common:定义了常用的枚举常量,工具类(如FileUtils ...

  5. 【Spring Boot】创建一个简单的Spring Boot的 Demo

    走进Spring Boot 文章目录 走进Spring Boot 环境搭建 新建Spring Boot项目 开始创建项目 配置JDK版本 和 Initializr Service URL 配置Proj ...

  6. Spring TestContext测试框架搭建

    同样是测试,JUnit和Spring TestContext相比,Spring TestContext优势如下: 1.Spring TestContext可以手动设置测试事务回滚,不破坏数据现场 2. ...

  7. Spring引用测试

    上下文 using System; using Spring.Core; using Spring.Aop; using System; using Spring.Core; using Spring ...

  8. android gps开发必备资料(含测试demo下载)

    入门资料参考: How accurate is Android GPS? Part 1: Understanding Location Data How accurate is Android GPS ...

  9. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试

    这一部分的主要目的是 配置spring-service.xml  也就是配置spring  并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...

  10. Spring MVC测试框架

    原文链接:http://jinnianshilongnian.iteye.com/blog/2004660 Spring MVC测试框架详解——服务端测试 博客分类: springmvc杂谈 spri ...

随机推荐

  1. 【T-SQL】分布抽取部分数据

    好吧,我确实不知道该怎么起这个标题,整了一个“分布”,感觉还有点高档,其实没啥技术含量,看完你就知道了.情况是这样,刚刚接到一个临时任务,需要让几个营业点的销售数据[变]少一点,就是在ERP的相关报表 ...

  2. 关于大数据企业信息查询的API该怎么写

    最近在看API相关的案例,做的是.net开发的工作 对API开发这块很是迷茫,不知道从哪入手,园子里面的朋友有没有研究这块的给点建议 公司目前准备做一款企业数据查询的网站,让我负责API接口这块,基于 ...

  3. php实现设计模式之 简单工厂模式

    作为对象的创建模式,用工厂方法代替new操作. 简单工厂模式是属于创建型模式,又叫做静态工厂方法模式,但不属于23种GOF设计模式之一.简单工厂模式是由一个工厂对象决定创建出哪一种产品类的实例. 工厂 ...

  4. JMeter专题系列(二)录制脚本

    环境 Badboy  version 2.1.1 JDK: 1.7.0_67 Apache  JMeter-2.11 ----------------------------------------- ...

  5. UML常用图

    序列图 活动图

  6. 字符编码笔记:ASCII,Unicode和UTF-8

    很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的,于是他们把这称为"字节". 再后来,他们又做了一些可以处理 ...

  7. iOS BUG: Unbalanced calls to begin/end appearance transitions for <XXXViewController: 0x7fcea3730650>.

    自定义TabBarController Push下一级Controller时 会报这样的错误:Unbalanced calls to begin/end appearance transitions ...

  8. Windows TCP连接数限制解决

    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "M ...

  9. 基于Tomcat的Solr3.5集群部署

    基于Tomcat的Solr3.5集群部署 一.准备工作 1.1 保证SOLR库文件版本相同 保证SOLR的lib文件版本,slf4j-log4j12-1.6.1.jar slf4j-jdk14-1.6 ...

  10. ERROR ITMS-90682: Invalid Bundle - The asset catalog at 'Payload/XXXXX/Assets.car' can't contain 16-bit or P3 assets if the app supports iOS 9.3 or earlier.

    刚升级Xcode 8, 幺蛾子又出现了.提交的时候出了这个问题. BTW,感谢google.以下为解决方案:‘ 在 Xcode 8 中,当你资源文件中[含有16位图]或者[图片显示模式γ值为'P3'] ...