Spring - JUnit整合测试
1、导包:test.jar - (依赖 aop.jar)
2、使用@RunWith注解创建spring容器 - @RunWith(SpringJUnit4ClassRunner.class)
3、使用@ContextConfiguration读取spring配置文件 - @ContextConfiguration("classpath:applicationContext.xml")
4、使用@Resource获取已装配bean的对象
package com.sikiedu.test; import javax.annotation.Resource; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.sikiedu.service.UserService; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class AopTest {
// 将名为userService的对象注入到UserService中
@Resource(name = "userService")
private UserService us; @Test
public void test2() { us.delete(); }
}
Spring - JUnit整合测试的更多相关文章
- JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示
一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...
- spring-注解配置-junit整合测试-aop
1 使用注解配置spring 1.1 步骤 导包4+2+spring-aop 1.为主配置文件引入新的命名空间(约束) 2.开启使用注解代理配置文件 3.在类中使用注解完成配置 1.2 将对象注册到容 ...
- Spring Boot从入门到放弃-Spring Boot 整合测试
站长资讯摘要:使用Spring Boot 整合测试,对Controller 中某个方法进行测试或者对Service,Mapper等进行测试,不需要运行项目即可查看运行结果是否和期望值相同,Spring ...
- JAVA框架 Spring junit整合单元测试
一.准备工作 1:Junit的需要的jar包: 2.spring的整合的jar包:spring-test-4.2.4.RELEASE.jar 3.代码实现 1) //导入整合的类,帮我们加载对应的配置 ...
- spring与junit整合测试
1.导包4+2+aop+test 2.配置注解 3.测试
- spring框架学习(三)spring与junit整合测试
package cn.mf.b_test; import javax.annotation.Resource; import org.junit.Test; import org.junit.runn ...
- Spring+Junit+Mock测试web项目,即Controller
准备:Maven依赖 <!-- Spring和MVC的包这里不列出来了,webmvc,aspects,orm,其他maven会自动导 --> <dependency> < ...
- Spring+Junit,测试事务时,一直回滚
研究了好长时间,都不知道原因,也不能解决. 控制台又没有报异常,但是就是一直回滚.注释掉spring声明式配置的代码,就能正确的更新数据. 从网上看了,别人的文章 http://blog.csdn.n ...
- Spring学习笔记(二)——Spring相关配置&属性注入&Junit整合
一.Spring的相关配置 1.1 Bean元素 class属性:被管理对象的完整类名 name属性:给Bean起个名字,能重复,能使用特殊字符.后来属性 id属性:给Bean起个名字,不能重复,不能 ...
随机推荐
- java script 数组去重两种方法
第一种方法: var arr=[1,1,2,3,4,4,4,5,6,6,6,6]; var arrb=Array(); for(var i=0;i<arr.length;i++) ...
- 数位dp——牛客多校H
/* x[1,A] y[1,B] x^y<C 或 x&y>C 把ABC拆成二进制后按位进行数位dp dp[pos][s1][s2][f1][f2] 表示从高到低第pos位,条件一状 ...
- Elasticsearch集群状态查看命令
_cat $ curl localhost:9200/_cat=^.^=/_cat/allocation/_cat/shards/_cat/shards/{index}/_cat/master/_ca ...
- NX二次开发-获取矩阵值UF_CSYS_ask_matrix_values
NX9+VS2012 #include <uf.h> #include <uf_csys.h> UF_initialize(); //获取WCS标识 tag_t WcsId = ...
- cordova 与 phonegap关系
Apache Cordova是PhoneGap贡献给Apache后的开源项目,是从PhoneGap中抽出的核心代码,是驱动PhoneGap的核心引擎.PhoneGap是一个开源的开发框架,使用HTML ...
- hdu多校第八场 1009 (hdu6665) Calabash and Landlord 计算几何/dfs
题意: 给定两个矩形,输出这两个矩形把平面分成了多少块. 题解: 本来是道计算几何的大讨论,被我生生写成了bfs. 离散化边,注意不重合的边中间要空出来一格,四周也要空出来一圈,然后暴力bfs计算一共 ...
- CodeForces 1166E The LCMs Must be Large
题目链接:http://codeforces.com/problemset/problem/1166/E 说明 LCM(一个集合) 为这个集合中所有元素的最小公倍数. 如果$A \subseteq B ...
- ActiveMQ任意文件写入漏洞(CVE-2016-3088)
上传webshell 容器用vulhub的 PUT一个jsp文件 MOVE到api目录 默认的ActiveMQ账号密码均为admin,首先访问http://your-ip:8161/admin/tes ...
- CSS3 RGBA等于RGB加上opacity吗?
在我们前端设计里有两篇教程: CSS3 RGBA colors使用说明 css3中opacity属性学习与实践,他们公别介绍了RGBA,RGB,opacity的用法,这里我们把这三个属性放在一起来考虑 ...
- 3.2_springBoot2.1.x检索之JestClient操作ElasticSearch
这里介绍Jest方式交互, 导入jest版本 <!--导入jest--> <dependency> <groupId>io.searchbox</groupI ...