spring+junit单元测试
<1>读取文件:
配置文件在classes下:locations = {"classpath*:/spring/applicationContext.xml"}
配置文件在web-inf下:locations = {"file:web/WEB-INF/applicationContext.xml"}
<2>实例类:
package com.test;
import java.util.List;
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.entity.User;
import com.service.impl.UserService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"file:web/WEB-INF/applicationContext.xml"})
public class PageTest {
@Autowired
private UserService userService;
@Test
public void testPage(){
// add your test code
}
}
}
spring+junit单元测试的更多相关文章
- spring && Cobertura && maven &&junit 单元测试以及测试覆盖率
1. 目的: junit 单元测试,Cobertura 测试覆盖率报告 项目目录结构 2. maven 配置 <project xmlns= ...
- spring junit 做单元测试,报 Failed to load ApplicationContext 错误
spring junit 做单元测试,报 Failed to load ApplicationContext 错误. 查找了好一会,最后发现.@ContextConfiguration(locatio ...
- Spring框架中整合JUnit单元测试的方法
一. 步骤: 1. 拷贝jar包: 1. JUnit-4.9.jar和spring-test-4.2.4.RELEASE.jar ; 2. 替换原来的main函数: 1. 在测试类上使用注解方式替换: ...
- spring框架学习(三)junit单元测试
spring框架学习(三)junit单元测试 单元测试不是头一次听说了,但只是听说从来没有用过.一个模块怎么测试呢,是不是得专门为一单元写一个测试程序,然后将测试单元代码拿过来测试? 我是这么想的.学 ...
- Spring完全基于Java配置和集成Junit单元测试
要点: 配置继承WebApplicationInitializer的类作为启动类,相当于配置web.xml文件 使用@Configuration注解一个类,在类中的方式使用@Bean注解,则表名该方法 ...
- Spring的AOP开发入门,Spring整合Junit单元测试(基于ASpectJ的XML方式)
参考自 https://www.cnblogs.com/ltfxy/p/9882430.html 创建web项目,引入jar包 除了基本的6个Spring开发的jar包外,还要引入aop开发相关的四个 ...
- Spring框架 JdbcTemplate类 @Junit单元测试,可以让方法独立执行 如:@Test
package cn.zmh.PingCe; import org.junit.Test; import org.springframework.jdbc.core.BeanPropertyRowMa ...
- 十二 Spring的AOP开发入门,整合Junit单元测试(AspectJ的XML方式)
创建web项目,引入jar包 引入Spring配置文件
- Spring之单元测试
引言 是否在程序运行时使用单元测试是衡量一个程序员素质的一个重要指标.使用单元测试既可以让我检查程序逻辑的正确性还可以让我们减少程序测试的BUG,便于调试可以提高我们写程序的效率.以前我们做单元测试的 ...
随机推荐
- SOAP(简单对象访问协议)
ylbtech-Miscellaneos:SOAP(简单对象访问协议) A,返回顶部 1, 简单对象访问协议是交换数据的一种协议规范,是一种轻量的.简单的.基于XML(标准通用标记语言下的一个子集)的 ...
- TensorFlow中与卷积核有关的各参数的意义
以自带models中mnist的convolutional.py为例: 1.filter要与输入数据类型相同(float32或float64),四个参数为`[filter_height, filter ...
- 转I2s
转自http://blog.csdn.net/ce123/article/details/6919954 I2S音频总线学习(二)I2S总线协议 一.I2S总线概述 音响数据的采集.处理和传输是多媒体 ...
- [CF442A] Borya and Hanabi (暴力bitmask)
题目链接:http://codeforces.com/problemset/problem/442/A 题目大意:给你n张卡片,你知道这n张卡片都是什么,但是不知道他们的位置.你每次可以请求朋友指出一 ...
- LeetCode 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- mac-文本编辑器
windows时代最喜欢的文本编辑器一直是ultraedit,但到了mac下,破解的ultraedit退出时会异常,于是琢磨着换编辑器,最终选择了sublime text2,百度下载,不注册也可以用. ...
- linux基础1——网络配置入门
1.IP地址配置 (1)临时IP更改 sudo ifconfig eth0 down 暂停接口 sudo ifconfig eth0 192.168.1.xx sudo ifconfig eth ...
- 树莓派摄像头模块转成H264编码通过RTMP实现Html输出
官方原帖 http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=45368&sid=b81f6551e478f0f6e172aa ...
- 1不等于1?numeric、decimal、float 和 real 数据类型的区别
大家有没有在SQL中遇见1不等于1(1<>1)的情形!?下面会有一个例子演示这个情形. 先简单介绍一下标题中的四种数值数据类型. 在T-SQL中,numeric和decimal是精确数值数 ...
- 虚拟机中CentOS 7下PHP环境配置
为了简单起见,虚拟机网卡设置为桥接模式 1.yum install httpd php 2.yum install mariadb 3.启动mariadb systemctl start maria ...