spring框架和junit框架结合使用案例
package ltssh; 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.lt.bean.Content;
import com.lt.dao.content.IContentDao; /**
*
* 类: JunitSpringTest <br>
* 描述: spring框架和junit框架结合使用案例 <br>
* 使用注解的方式读取配置文件,自动注入dao进行测试
* 有点:干净整洁,代码优雅
* 注意:@RunWith @ContextConfiguration这两个注解的使用
* 我是导入了最新版本的junit.jar和hamcrest-core-1.3.jar
* junit-4.4.jar版本的不支持
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class JunitSpringTest { @Autowired
private IContentDao contentDao; @Test
public void handler(){
Content content = contentDao.get(1);
System.out.println(content.getTitle());
}
}
package ltssh;
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.lt.bean.Content;
import com.lt.dao.content.IContentDao;
/**
*
* 类: JunitSpringTest <br>
* 描述: spring框架和junit框架结合使用案例 <br>
* 使用注解的方式读取配置文件,自动注入dao进行测试
* 有点:干净整洁,代码优雅
* 注意:@RunWith @ContextConfiguration这两个注解的使用
* 我是导入了最新版本的junit.jar和hamcrest-core-1.3.jar
* junit-4.4.jar版本的不支持
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class JunitSpringTest {
@Autowired
private IContentDao contentDao;
@Test
public void handler(){
Content content = contentDao.get(1);
System.out.println(content.getTitle());
}
}
spring框架和junit框架结合使用案例的更多相关文章
- Spring整合JUnit框架进行单元测试代码使用详解
一.Spring提供的JUnit框架扩展: 1. AbstractSpringContextTests:spring中使用spring上下文测试的Junit扩展类,我们一般不会使用这个类来进行单元 ...
- Spring框架下Junit测试
Spring框架下Junit测试 一.设置 1.1 目录 设置源码目录和测试目录,这样在设置产生测试方法时,会统一放到一个目录,如果没有设置测试目录,则不会产生测试代码. 1.2 增加配置文件 Res ...
- ssm项目框架搭建(增删改查案例实现)——(SpringMVC+Spring+mybatis项目整合)
Spring 常用注解 内容 一.基本概念 1. Spring 2. SpringMVC 3. MyBatis 二.开发环境搭建 1. 创建 maven 项目 2. SSM整合 2.1 项目结构图 2 ...
- Spring(3)—— Junit框架单元测试
Junit主要用于单元测试,即白盒测试.它是一个开源的由JAVA开发的一个用于测试的框架. Junit的几个基本概念:TestCase,TestSuite,TestFixtrue TestCase:代 ...
- spring、spring mvc、mybatis框架整合基本知识
学习了一个多月的框架知识了,这两天很想将它整合一下.网上看了很多整合案例,基本都是基于Eclipse的,但现在外面公司基本都在用Intellij IDEA了,所以结合所学知识,自己做了个总结,有不足之 ...
- spring+springMVC+mybatis的框架项目基础环境搭建
上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...
- 整合Spring框架和MyBatis框架
------------------------siwuxie095 整合 Spring 框架和 MyBatis 框架 ...
- SSM(spring,springMVC,Mybatis)框架的整合
这几天想做一个小项目,所以搭建了一个SSM框架. 1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Joh ...
- Spring Boot从入门到精通(九)整合Spring Data JPA应用框架
JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...
随机推荐
- JAVA Day2
标识符(类名:变量.属性.方法名: ) 组成:类名开头不能是数字,只能有字母数字_$组成. 命名规范: 类名每一个单词首字母大写(HelloWorld大驼峰法则) ...
- css的重置和原子类的使用
@charset "utf-8";/* Reset Definitions*/body, div, p, a, ul, ol, li, dl, dt, dd, h1, h2, h3 ...
- 20145223《Java程序程序设计》实验报告二
实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步骤 (一)单元测试 ...
- 我的c++学习(3)字符的输入输出
#include "stdafx.h" #include<iostream> using namespace std; int main(void) { /* char ...
- MySql 查询数据库中所有表名
查询数据库中所有表名select table_name from information_schema.tables where table_schema='csdb' and table_type= ...
- Codeforces Round #346 (Div. 2)
前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int ...
- Redis 事务总结
特点: 对单个客户端可以执行连续性事务(在一个线程内): 执行命令要排队: mutil类似begin trans; exec 类似 commit; discard 用于放弃事务: watch ...
- qq邮箱邮我组件
http://openmail.qq.com/cgi-bin/qm_help_mailme?sid=uvkgSu7e0aOrc0Qc&t=open_mailme 邮我 使用"邮我&q ...
- linux下查找可执行文件
linux下查找可执行文件 ls -F|grep "*" 我们来看看ls -F的作用: -F开关对可执行文件添加一个*号,为目录添加一个/号,为符号链接添加一个@号. http:/ ...
- (转)Array.prototype.slice.call自解
很多框架或者库里面都会有这句的使用,最多的还是通过Array.prototype.slice.call(arguments,0)把arguments这个伪数组转换为真正的数组.但为什么可以这么做,却一 ...