spring-mvc junit测试
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /**
* Created by jecyhw on 16-5-12.
*/
@RunWith(SpringJUnit4ClassRunner.class)//使用Spring整合Junit的测试类测试
@ContextConfiguration(locations = {//spring-mvc配置文件
"file:src/main/resources/applicationContext.xml"
})
@TestPropertySource(locations = {//所用到的properties文件
"file:src/main/resources/mongodb.properties",
"file:src/main/resources/weixin.properties"
})
abstract public class BaseTest extends AbstractJUnit4SpringContextTests {
//其他所有test继承BaseTest即可
}
//简单的测试类
public class EventDaoTest extends BaseTest{ @Resource
EventDao eventDao; @Test
public void list() {
JsonUtil.writeAsString(eventDao.list());
}
}
spring-mvc junit测试的更多相关文章
- Struts2+Spring+Mybatis+Junit 测试
Struts2+Spring+Mybatis+Junit 测试 博客分类: HtmlUnit Junit Spring 测试 Mybatis package com.action.kioskmoni ...
- Spring整合junit测试
本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...
- Spring MVC如何测试Controller(使用springmvc mock测试)
在springmvc中一般的测试用例都是测试service层,今天我来演示下如何使用springmvc mock直接测试controller层代码. 1.什么是mock测试? mock测试就是在测试过 ...
- Spring MVC的测试
测试是保证软件质量的关键. 与 Spring MVC 相关的测试,主要涉及控制器的测试. 为了测试Web项目通常不需要启动项目,需要一些Servlet相关的一些模拟对象,比如MockMVC.MockH ...
- Spring集成JUnit测试
1.程序中有Junit环境2.导入一个jar包.spring与junit整合jar包 spring-test-3.2.0.RELEASE.jar3.测试代码 @RunWith(SpringJUnit4 ...
- 原创:Spring整合junit测试框架(简易教程 基于myeclipse,不需要麻烦的导包)
我用的是myeclipse 10,之前一直想要用junit来测试含有spring注解或动态注入的类方法,可是由于在网上找的相关的jar文件进行测试,老是报这样那样的错误,今天无意中发现myeclips ...
- Spring MVC 异步测试
从spring3.2开始,支持servlet3的异步请求,这对于处理耗时的请求如缓慢的数据库查询是非常有好处的,不至于很快的耗光servlet的线程池,影响可扩展性. 让我们先来了解一下servlet ...
- Spring之junit测试集成
简介 Spring提供spring-test-5.2.1.RELEASE.jar 可以整合junit. 优势:可以简化测试代码(不需要手动创建上下文,即手动创建spring容器) 使用spring和j ...
- Spring与Junit测试整合
一.引入spring测试包:text包 二.@RunWith:指定spring对junit提供的一个运行器 @ContextConfiguration: locations指定spring配置文件位 ...
- Spring项目JUnit测试报错ClassNotFoundException解决
Eclipse项目上有红色感叹号,各包显示正常.用JUnit测试部分能运行,部分报错,报错如下: Class not found UserTestjava.lang.ClassNotFoundExce ...
随机推荐
- 无法获得VMCI 驱动程序的版本: 句柄无效的解决方法
关闭虚拟机,找到安装路径,用记事本打开.vmx结尾的文件 将vmci0.present = "TRUE"改为vmci0.present = "FALSE"保存
- bzoj 4821 [Sdoi2017]相关分析
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4821 题解 做法显然 就是维护一颗线段树 里面装4个东西 区间x的和 区间y的和 区间$x^ ...
- [洛谷P4185] [USACO18JAN]MooTube
题目链接: 传送门 题意: 给定一颗N个节点的树,定义两点距离为他们之间路径中边权最小值. Q次询问K,V,询问到V距离>=K的点有多少(不含V) 呃呃呃呃考试的时候直奔了T3,结果公式推挂了( ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- org.codehaus.jettison.json.JSONObject使用方法
public static void main(String[] args) { System.out.println("测试开始"); File file = new File( ...
- Plugging an Unplugged Pluggable Database
1.unplug To unplug a PDB, you first close it and then generate an XML manifest file. The XML file co ...
- vue 模拟后台数据(加载本地json文件)调试
首先创建一个本地json文件,放在项目中如下 { "runRedLight":{ "CurrentPage": 1, "TotalPages" ...
- qconshanghai2015
http://2015.qconshanghai.com/schedule 大会日程 2015年10月15日 星期四 08:30 开场致辞 地点 光大宴会厅 专题 主题演讲 数据分析与移动开发工具 ...
- 【ADO.NET】 使用通用数据库操作类Database (SQL Server)
一.Web.config配置 <connectionStrings> <add name="constr_name" connectionString=" ...
- 定时器、线程queue、进程池和线程池
1.定时器 指定n秒后,执行任务 from threading import Timer,current_thread import os def hello(): print("%s he ...