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的单元测试 ...
随机推荐
- MVC网站后台分离
1.新建一个项目TestAdmin项目类型随便选一个,待会删掉,因为这里我只需要解决方案名称 [项目存放于F盘 F:\TestAdmin] 2.新建一个 ZGJ.Web 的前台MVC项目,将开 ...
- C++从函数返回指针
C++ 允许您从函数返回指针.为了做到这点,必须声明一个返回指针的函数,如下所示: int * myFunction() { . . . } 另外,C++ 不支持在函数外返回局部变量的地址,除非定义局 ...
- codefirst mvc Self referencing loop detected for property
登录时,json序列化用户类时提示错误"Self referencing loop detected for property--",经过5个小时的查找,发现原因可能是,用户类包含 ...
- 线性规划?数学?差分约束?Good Bye 2016 C
http://codeforces.com/contest/750/problem/C 反正我不会这道题...为什么那么多人做出来了...我好菜.jpg 题目大意:cf每个人都有分数,每次都会在div ...
- adb shell dumpsys
adb shell dumpsys activity activities -- class/packagename adb shell dumpsys batterystate --reset ...
- mysql B+树 Cardinality MRR
B+树索引并不能找到一个给定键值的具体行,而是被查找数据行所在的页.然后数据库通过把页读入到内存,再在内存中进行查找,最后得到想要查找的数据. Show index from table. Cardi ...
- tensorflow安装相关的
1 Install pip and Virtualenv sudo apt-get install python-pip python-dev python-virtualenv2 Create a ...
- SpringMVC的@ModelAttribute注解简单使用(用户修改信息)
例如有一个User对象,我们要修改他的值,但是不能修改他的密码!通过表单提交数据之后,password为null,会把原对象的passwod覆盖掉.这时候可以用@ModelAttribute注解处理. ...
- STS中Maven配置
最近接触maven, 配置过程中记录一下. STS是解压版的,启动后,可以看到已经有了Maven插件, , 但是,STS也同时给你了一个Maven,但是通常不建议使用STS自带的maven.使用默认的 ...
- html 超链接(a)详细讲解
a:link : http://www.cnblogs.com/yangfeng/archive/2009/07/25/1530962.html 超级链接 超级链接是网站中使用比较频繁的HTML元素, ...