Spring整合Junit框架
一.开发环境
eclipse版本:4.6.1
maven版本:3.3.3
junit版本:4.12
spring版本:4.1.5.RELEASE
JDK版本:1.8.0_111
二.项目结构
图
三.文件清单
pom.xml
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>springJunit</groupId>
- <artifactId>springJunit</artifactId>
- <version>1.0</version>
- <packaging>war</packaging>
- <properties>
- <!-- spring版本号 -->
- <spring.version>4.1.5.RELEASE</spring.version>
- <!-- junit版本号 -->
- <junit.version>4.12</junit.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </project>
JunitTest.java
- package com.dqiang;
- public interface JunitTest {
- public String sayHelloWorld(String word);
- }
JunitTestImpl.java
- package com.dqiang.impl;
- import org.springframework.stereotype.Service;
- import com.dqiang.JunitTest;
- @Service
- public class JunitTestImpl implements JunitTest {
- public String sayHelloWorld(String word) {
- return "hello->" + word;
- }
- }
JTest.java
- package springJunit;
- 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.dqiang.JunitTest;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = { "classpath:springmvc.xml" })
- public class JTest {
- @Autowired
- private JunitTest junitTest;
- @Test
- public void sayHelloWorld() {
- String result = junitTest.sayHelloWorld("junit Test");
- System.out.println(result);
- }
- }
说明:
@RunWith 使用RunWith注解改变JUnit的默认执行类,并实现自已的Listener在平时的单元测试,如果不使用RunWith注解,那么JUnit将会采用默认的执行类Suite执行。
@ContextConfiguration 可以通过该属性手工指定 Spring 配置文件所在的位置,可以指定一个或多个 Spring 配置文件。
Demo下载:点击下载
来源:https://www.cnblogs.com/jpfss/p/8073091.html
Spring整合Junit框架的更多相关文章
- Spring整合JUnit框架进行单元测试代码使用详解
一.Spring提供的JUnit框架扩展: 1. AbstractSpringContextTests:spring中使用spring上下文测试的Junit扩展类,我们一般不会使用这个类来进行单元 ...
- Spring整合Junit框架进行单元测试Demo
一.开发环境 eclipse版本:4.6.1 maven版本:3.3.3 junit版本:4.12 spring版本:4.1.5.RELEASE JDK版本:1.8.0_111 二.项目结构 图 三. ...
- 【Spring】Spring系列7之Spring整合MVC框架
7.Spring整合MVC框架 7.1.web环境中使用Spring 7.2.整合MVC框架 目标:使用Spring管理MVC的Action.Controller 最佳实践参考:http://www. ...
- 【SSH框架】系列之 Spring 整合 Hibernate 框架
1.SSH 三大框架整合原理 Spring 与 Struts2 的整合就是将 Action 对象交给 Spring 容器来负责创建. Spring 与 Hibernate 的整合就是将 Session ...
- spring整合junit报错
1.Could not autowire field: private javax.servlet.http.HttpServletRequest 参考:https://www.cnblogs.com ...
- Spring整合EHCache框架
在Spring中使用缓存可以有效地避免不断地获取相同数据,重复地访问数据库,导致程序性能恶化. 在Spring中已经定义了缓存的CacheManager和Cache接口,只需要实例化便可使用. Spr ...
- Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)
1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...
- Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。
1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...
- Spring整合junit测试
本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...
随机推荐
- window系统 查看端口 被哪个进程占用了
一.在windows命令行窗口下执行:运行--cmdC:\>netstat -aon|findstr "8080" TCP 127.0.0.1:80 0. ...
- SVN报错 Not Found In Revision 不支持空目录
如果你要初始化上传的SVN目录为空,有可能会报这个错误 解决方法:在SVN下新建一个目录即可
- JS 九宫格算法 用原生js实现
九宫格算法核心: 利用控件索引index计算出控件所在的行数和列数: 利用控件计算出left距离: 利用控件计算出top距离: 写特效时需要用到定位 公式: 行 row=parseInt(i/cols ...
- [CREC2007/CQOI2014]robotic sort
Description 一个实验室里有n个长短不一的试管.你的任务是编写一段程序,用机器臂把它们按照高度从小到大的顺序排列. 对于高度相同的试管,排序前后的相对位置应保持不变.排序方法如图所示. 排序 ...
- 基本的查询流【MSSQL】
4个DML(Data Manipulation Language)命令 SELECT INSERT UPDATE DELETE 查询语法有一个特有的固定顺序 SELECT - FROM - WHERE ...
- (转) 淘淘商城系列——使用SolrJ查询索引库
http://blog.csdn.net/yerenyuan_pku/article/details/72908538 我们有必要在工程中写查询索引库的代码前先进行必要的测试.我们先到Solr服务页面 ...
- HDU_3496_(二维费用背包)
Watch The Movie Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- jmeter接口测试小结
摘自:http://www.cnblogs.com/houzhizhe/p/6839736.html JMeter做http接口压力测试 测前准备 用JMeter做接口的压测非常方便,在压测之前我们需 ...
- offset 后 指针数组转换
AcDbObjectId pidoffset; AcDbPolyline *plineOffset; AcDbVoidPtrArray ptarr=NULL; pline->getOffsetC ...
- 通过Oracle函数SQL实现C# String.Format字符串格式化功能
语言国际化要求,开发上要求Oracle数据库SQL中对应的返回信息-Message,实现一个通用函数调用,比如:提示信息内容:条码123456当前工站在FCT!”,即通用的信息内容格式化标准为:“条码 ...