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之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...
随机推荐
- obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
接下来我就简单跟大家介绍一下利用nginx来搭建流媒体服务器. 我选择的是腾讯云服务器 1.下载nginx-rtmp-module: nginx-rtmp-module的官方github地址:http ...
- Flink源码阅读(1.7.2)
目录 Client提交任务 flink的图结构 StreamGraph OptimizedPlan JobGraph ExecutionGraph flink部署与执行模型 Single Job Jo ...
- Netty,Thrifty
小白科普:Netty有什么用? https://mp.weixin.qq.com/s/PTKnRQ_hLf8BBPYnywLenA Thrifty 是基于.net Attribute 实现了标准 Th ...
- 11.7NOIP模拟题
/* 有循环节 */ #include<cstdio> #include<cstring> #include<iostream> #include<algor ...
- 【题解】TES-Intelligence Test
[题解]\(TES-Intelligence\) \(Test\) 逼自己每天一道模拟题 传送:\(TES-Intelligence\) \(Test\) \([POI2010]\) \([P3500 ...
- ROS-USB摄像头
前言:演示使用usb摄像头功能,推荐使用方法二. 首先要有一个usb摄像头,本次使用的是罗技(Logitech)摄像头. 一.使用软件库里的uvc-camera功能包 1.1 检查摄像头 lsusb ...
- c语言—栈区,堆区,全局区,文字常量区,程序代码区 详解
转:http://www.cnblogs.com/xiaowenhui/p/4669684.html 一.预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分1.栈区(sta ...
- select多选
1.css <style> .divBox{ width:400px; margin:100px auto; } .divBox span{ vertical-align:top; dis ...
- YumRepo Error: All mirror URLs are not using ftp, http[s] or file
有台机器使用Yum的时候,报错如下: YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. $releaseve ...
- 无法连接到已配置的web服务器
问题:如题,asp.net WebForm的项目,在vs中选择aspx文件在浏览器中查看时候回报该错误. 网上最多的解决方案是防火墙的原因,说关闭防火墙就可以了.但问题是我另一个项目没有问题啊,所以不 ...