Spring的测试

spring测试要引用junit及spring-test

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

代码:

配置文件的引入:

单个文件:@ContextConfiguration(locations ="classpath:spring-mybatis.xml")

多个文件:@ContextConfiguration(locations ={"classpath:spring-mybatis.xml","classpath:application-context-provider.xml"})

import com.zoe.aop.dto.*;
import com.zoe.aop.service.out.DeptService;
import org.junit.Assert;
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;

/**
 * Created by gyoung on 2016/1/23.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations ={"classpath:spring-mybatis.xml","classpath:application-context-provider.xml"})
public class DeptServerTest {

    @Autowired
    private DeptService deptService;

    @Test
    public void deptSelectTest() {
        DeptDto model= deptService.getOneById("2");
        Assert.assertTrue(model.getId().equals("2"));
    }

    @Test
    public void updateTest(){
        DeptDto model= new DeptDto();
        model.setId("2");
        model.setName("111");
        deptService.update(model);
        String id=model.getId();
    }

    @Test
    public void pageTest(){
        QueryPage page=new QueryPage(1,5);
        ServiceResultT<CorePageList> resultT= deptService.getList(page);
    }

    @Test
    public void deleteTtest(){
        ServiceResult result= deptService.deleteById("1203");
    }

    @Test
    public void updateDbTest(){

    }
}
时间: 2024-12-08 06:59:12

Spring的测试的相关文章

Spring+mybatis测试项目总结

1.项目目的a.通过Spring+Mybatis实现通过web访问达成mySql的操作b.理解Spring+Mybatis的配置c.理解maven对项目的管理2.配置文件a.采用maven约定结构,src/main/java.src/main/resources.src/main/test b.基本springMVC+Mybatis需要用到的jar spring-web.spring-webmvc.spring-core.spring-beans.spring-context.spring-co

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

这一部分的主要目的是 配置spring-service.xml  也就是配置spring  并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)在这个基础上面 继续进行spring的配置. 回顾上面  我们已经成功测试通过了Mybatis的配置. 这时候的目录结构是: 一:下面我们继续补充目录结构,在com.peakfortake的文件目录项目 

Spring TestContext测试框架搭建

同样是测试,JUnit和Spring TestContext相比,Spring TestContext优势如下: 1.Spring TestContext可以手动设置测试事务回滚,不破坏数据现场 2.在测试类中不用手动装配bean,只要一个@Autowired即可自动装配 ----------------分割线--------------------------- 本文记录web project和java project如何使用TestContext测试框架,首先介绍web project 现总

使用 intellijIDEA 创建 maven 工程进行 Spring ioc 测试

使用 intellijIDEA 创建 maven 工程进行 Spring ioc 测试 ioc 概念 控制反转(Inversion of Control,缩写为IOC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度.其中最常见的方式叫做依赖注入(Dependency Injection,简称DI).通过控制反转,对象在被创建的时候,由一个调控系统内所有对象的外界实体,将其所依赖的对象的引用传递给它.也可以说,依赖被注入到对象中. IOC和DI区别 IOC: 控制反转,把对象

Spring TestContext测试框架

1.基于注解的TestContext测试框架,它采用注解技术可以让POJO成为Spring的测试用例,可以运行在Junit3.8 Junit4.4 TestNG等测试框架之下 2.直接使用Junit测试Spring程序存在的不足 1).导致Spring容器多次初始化问题 根据JUnit测试用例的调用流程,每执行一个测试方法都会重新创建一个测试用例实例并调用其setUp() 方法. 由于在一般情况下,我们都在setUp() 方法中初始化Spring 容器,这意味着测试用例中有多少个测试方法,Spr

spring ----&gt; aop测试需要的Maven依赖/测试时发生的一个exception

1 <properties> 2 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 3 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 4 <!-- spring版本号 --> 5 <spring.version>4.2.4.RELEASE

spring junit4 测试

@Service @ContextConfiguration(locations = { "classpath:config/applicationContext.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false) public class Un

maven+spring+junit测试要注意的事情

使用maven方式创建webapp工程的资料网上一大堆,在这里也不详细说了.在创建完成之后,里面说到要转动态web工程时要切换为3.0版本,但是我本地切换不了,网上的方法好像也没用,暂时也没用到这块.等SSM框架搭建好了之后再细说这块.今天要说的是之前按照网上一个教程搭建SSM框架时遇到的针对spring针对junit单元测试的坑,因为涉及到maven的版本管理,一直没跳出来.昨天下午给解决了.有可能别的eclipse或者其他环境不会遇到这问题,但这里我还是要提醒一下.按照以下教程https:/

就是这么简单(续)!使用 RestAssuredMockMvc 测试 Spring MVC Controllers

就是这么简单(续)!使用 RestAssuredMockMvc 测试 Spring MVC Controllers 转载注明出处:http://www.cnblogs.com/wade-xu/p/4311205.html 接我前面一篇文章关于RestAssured测试Restful web service的, RestAssured还有一个功能, 使用RestAssuredMockMvc 单元测试你的Spring MVC Controllers, 这个MockMvc 是建立在Spring Moc