spring + junit 测试
spring + junit 测试
需要一个工具类
package com.meizu.fastdfsweb;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-context.xml")
public abstract class BaseSpringContextUnitTest {
}
测试例子:
package com.meizu.fastdfsweb.entity;
import junitx.framework.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.meizu.fastdfsweb.BaseSpringContextUnitTest;
public class ClusterConfigTest extends BaseSpringContextUnitTest {
@Autowired
ClusterConfig clusterConfig;
@Test
public void testGetClusterNum() {
System.out.println(clusterConfig);
Assert.assertEquals(2, clusterConfig.getClusterNum());
}
}
spring + junit 测试的更多相关文章
- Spring Junit测试(非web,即不包含Controller测试)
使用Spring-Test对Spring框架进行单元测试 配置过程: lib加入导入spring-test.jar和junit包 或者使用Maven依赖: <dependency> < ...
- maven+spring+junit测试要注意的事情
使用maven方式创建webapp工程的资料网上一大堆,在这里也不详细说了.在创建完成之后,里面说到要转动态web工程时要切换为3.0版本,但是我本地切换不了,网上的方法好像也没用,暂时也没用到这块. ...
- Struts2+Spring+Mybatis+Junit 测试
Struts2+Spring+Mybatis+Junit 测试 博客分类: HtmlUnit Junit Spring 测试 Mybatis package com.action.kioskmoni ...
- spring boot web开发 简单的增删改查和spring boot 自带的Junit测试 案例
创建 web项目 配置pom.xml文件 ------相当于jar包 配置application.yml -----配置文件(spring数据库连接.server服务.logging日志等) 创建 ...
- 原创:Spring整合junit测试框架(简易教程 基于myeclipse,不需要麻烦的导包)
我用的是myeclipse 10,之前一直想要用junit来测试含有spring注解或动态注入的类方法,可是由于在网上找的相关的jar文件进行测试,老是报这样那样的错误,今天无意中发现myeclips ...
- Spring Boot 解决方案 - JUnit 测试
简单的 JUnit 项目 回顾一下创建并运行简单的 JUnit 测试项目,先添加 JUnit 依赖然后编写类似如下模板的测试类,使用 IDE 的话直接用插件运行就行, 使用 Maven 的话运行命令 ...
- Spring整合junit测试
本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...
- Spring框架下Junit测试
Spring框架下Junit测试 一.设置 1.1 目录 设置源码目录和测试目录,这样在设置产生测试方法时,会统一放到一个目录,如果没有设置测试目录,则不会产生测试代码. 1.2 增加配置文件 Res ...
- Spring+Junit+Mock测试web项目,即Controller
准备:Maven依赖 <!-- Spring和MVC的包这里不列出来了,webmvc,aspects,orm,其他maven会自动导 --> <dependency> < ...
随机推荐
- [转帖]IP地址和CIDR
IP地址和CIDR https://www.cnblogs.com/cocowool/p/8303795.html 感谢原作者 自己竟然忘记了 classless inter-domain route ...
- SpringBoot起飞系列-国际化(六)
一.前言 国际化这个功能可能我们不常用,但是在有需要的地方还是必须要上的,今天我们就来看一下怎么在我们的web开发中配置国际化,让我们的网站可以根据语言来展示不同的形式.本文接续上一篇SpringBo ...
- DevOps 之 Jenkins 安装、配置、美化、插件及常见错误处理
继续上一篇的话题,既然已经搭建了 GitLab 的代码仓库,那么现在就可以开始进行下一步持续集成环境的搭建了.公司准备利用 Jenkins CI 进行持续集成,本文记录了 Jenkins 的安装.基础 ...
- JS基础_for循环
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 今天朋友带领去谷歌ok2eat 餐厅吃免费午餐
中午去队友公司免费吃饭.朋友带我们去她的楼下吃,就算是googler真的也不是所有cafe都知道,感谢朋友带领.
- js扩展Date对象的方法,格式化日期格式(prototype)
扩展:Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, ...
- Java web 项目 web.xml 配置文件加载过程
转载自:http://blog.csdn.net/luoliehe/article/details/46884757#comments WEB加载web.xml初始化过程: 在启动Web项目时,容器( ...
- 6.声明式异常处理、I18N
声明式异常处理 1.在Action 中进行异常映射 <exception-mapping result="error" exception="java.sql.SQ ...
- 3.Linux常用基本命令
1.帮助手册 man --help 2.日期类 data,cal -------------文件目录管理类的命令 3.显示当前目录 pwd 4.cd切换目录 cd .. 返回上级目录 cd / ...
- textarea框自适应高度
export function autoTextarea(elem, extra, maxHeight){ /**textarea文本域随内容的多少而调整高度 */ extra = extra || ...