如果是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. 自己实现简单的AOP(四)自动初始化代理对象

    前面三篇随笔,已经完成了AOP的核心功能,但 代理对象的初始化还是有些麻烦,本文将解决该问题. Demo 片段如下: public class HomeController : Controller ...

  2. webapi文档描述-swagger

    最近做的项目使用mvc+webapi,采取前后端分离的方式,后台提供API接口给前端开发人员.这个过程中遇到一个问题后台开发人员怎么提供接口说明文档给前端开发人员,最初打算使用word文档方式进行交流 ...

  3. nodejs连接mongodb的方法

    一. var express = require('express'); var mongodb = require('mongodb'); var app = express(); app.use( ...

  4. 转载:《TypeScript 中文入门教程》 16、Symbols

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 介绍 至ECMAScript 2015开始,symbol成为了一种新的原始类型,就像n ...

  5. DDD开发框架ABP之动态Web API层

    建立动态Web API 控制器 ASP.NET Boilerplate 能够自动为您的应用层产生Web API层.比如说我们有如下的一个应用服务: public interface ITaskAppS ...

  6. js实现右下角可关闭最小化div

    本实例使用Javascript实现右下角可关闭最小化div,可以用于展示推荐内容,效果预览网址:http://keleyi.com/keleyi/phtml/xuanfudiv/3.htm效果图片: ...

  7. jQuery静态方法isPlainObject,isEmptyObject方法使用和源码分析

    isPlainObject方法 测试对象是否是纯粹的对象(通过 "{}" 或者 "new Object" 创建的) 示例: //测试是否为纯粹的对象 jQuer ...

  8. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十二)水情雨情模块

    config.xml文件的配置如下: <widget label="水情" icon="assets/images/water.png" config=& ...

  9. 用VSCode写python的正确姿势(转载)

    最近在学习python,之前一直用notepad++作为编辑器,偶然发现了VScode便被它的颜值吸引.用过之后发现它启动快速,插件丰富,下载安装后几乎不用怎么配置就可以直接使用,而且还支持markd ...

  10. 在VM虚拟机上安装Microsoft Dynamics CRM 2016 步骤图解及安装注意事项

    安装Dynamics CRM 2016环境配置要求: 系统版本:Windows Server 2012 R2(必须) SQL 版本: SQLServer2014SP1-FullSlipstream-x ...