Spring测试
测试类添加两个注解
@RunWith(SpringJUnit4ClassRunner.class)和@ContextConfiguration(locations = "classpath:applicationContext.xml")
配置文件如果有多个,可以传个数组进去@ContextConfiguration({"classpath:spring/spring-dao.xml","classpath:spring/spring-service.xml"})
也是可以用通配符
@ContextConfiguration(locations = "classpath:spring/spring-*.xml")
如下: @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class ShoppingServiceImplTest {
@Resource
private ShoppingService service; @Test
public void addGoodsToCart() throws Exception {
UserShoppingCart cart=new UserShoppingCart();
cart.setCartId(UUID.randomUUID().toString());
cart.setUserUserId("f3544efc-5c12-470e-b22e-80kfh30bbec1");
cart.setProductId("1");
cart.setShopId(1);
cart.setProductNum(2);
int status=service.addGoodsToCart(cart); assertTrue(status==1); } }
Spring测试的更多相关文章
- 一个简单的Spring测试的例子
在做测试的时候我们用到Junit Case,当我们的项目中使用了Sring的时候,我们应该怎么使用spring容器去管理我的测试用例呢?现在我们用一个简单的例子来展示这个过程. 1 首先我们新建一个普 ...
- Spring入门(二)— IOC注解、Spring测试、AOP入门
一.Spring整合Servlet背后的细节 1. 为什么要在web.xml中配置listener <listener> <listener-class>org.springf ...
- 最“高大上”的Spring测试:Spring Test
我想给大家介绍一款非常实用.且高端大气上档次的spring测试,在这里,我要强烈推荐使用Spring的Test Context框架,为什么呢?俗话说,“货比三家不上当”,要搞清楚这个问题,我们先来看一 ...
- Spring-----注解开发和Spring测试单元
一.注解开发 导入jar包;spring-aop-xxx.jar 导入约束:(在官方文档xsd-configuration.html可找) <beans xmlns="http://w ...
- 使用junit进行Spring测试
这几天在做SpringMVC的项目,现在总结一下在测试的时候碰到的一些问题. 以前做项目,是在较新的MyEclipse(2013)上面进行Maven开发,pom.xml 文件是直接复制的,做测试的时候 ...
- Spring测试框架JUnit4.4 还蛮详细的
TestContext 可以运行在 JUnit 3.8.JUnit 4.4.TestNG 等测试框架下. Spring的版本2.5+JUnit4.4+log4j1.2.12 @RunWith(Spri ...
- spring 测试类test测试方法
实例掩码地址为:孔浩组织结构设计 web.xml配置文件: <!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 --> <context-param ...
- spring测试框架的使用
junit的使用 1.加入 junit jar包 <dependency> <groupId>junit</groupId> <artifactId>j ...
- spring测试实例
我们以前要进行单元测试,必须先得到ApplicationContext对象,再通过它得到业务对象,非常麻烦,重复代码也多.基于spring3的单元测试很好的解决了这个问题 基于spring3的单元测试 ...
随机推荐
- MyBatis-Generator 逆向工程(生成异常缺少部分的方法)
今日在使用 MyBatis-Generator 逆向工程时遇到了生成 mapper.java , mapper.xml 时缺少部分方法. 正常的 Mapper.java 示例: public in ...
- IntelliJ Idea 14 安装 Golang 插件 google-go-lang-idea-plugin 的方法
IDEA 的编辑器都很强悍,所以现在学Go 也想用他啊,无奈这个插件搞了好久,整理了下流程记录下 1. 当然是下载 IDEA 编辑器了 http://www.jetbrains.com/idea/do ...
- CodeForces 711D Directed Roads
计数,模拟. 首先观察一下给出的图的特点: $1.$一定存在环. $2.$可能存在多个环. 我们对每个环计算方案数,假设环$C$上包含$x$条边,那么把环$C$破坏掉的方案数有${2^x} - 2$种 ...
- StringMVC(拦截器)
单个拦截器 使用jar包 创建FirstController.java @Controller public class FirstController { @RequestMapping(" ...
- c++ 随手记
强类型的理解 先定义一些基础概念 Program Errors trapped errors.导致程序终止执行,如除0,Java中数组越界访问 untrapped errors. 出错后继续执行,但可 ...
- git 克隆到本地linux目录的2种方式
登录到gitlab查看2种不同的地址 ssh 类型 地址 git@inc.xxxx:shiwf/xxxAdmin.git http类型 地址 http://inc.xxxx:8000/shiwf/xx ...
- 10、 iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile
Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数是图片文件的路径. 两种 ...
- Difference between TCP and UDP
refered from http://www.cyberciti.biz/faq/key-differences-between-tcp-and-udp-protocols/ TCP UDP Rel ...
- Code Sign error: No code signing identities found: No valid signing identities
Code Sign error: No code signing identities found: No valid signing identities 解决办法:如果证书可获取,最简办法就是把所 ...
- 利用虚函数减少导出DLL的头文件依赖
概要 设想这样一个场景:我有一个类FunClass,它的声明位于FunClass.h,并且在FunClass.h中,我还引用了secret.h. 现在我需要把FunClass导出成DLL文件供别人二次 ...