测试类添加两个注解
@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测试的更多相关文章

  1. 一个简单的Spring测试的例子

    在做测试的时候我们用到Junit Case,当我们的项目中使用了Sring的时候,我们应该怎么使用spring容器去管理我的测试用例呢?现在我们用一个简单的例子来展示这个过程. 1 首先我们新建一个普 ...

  2. Spring入门(二)— IOC注解、Spring测试、AOP入门

    一.Spring整合Servlet背后的细节 1. 为什么要在web.xml中配置listener <listener> <listener-class>org.springf ...

  3. 最“高大上”的Spring测试:Spring Test

    我想给大家介绍一款非常实用.且高端大气上档次的spring测试,在这里,我要强烈推荐使用Spring的Test Context框架,为什么呢?俗话说,“货比三家不上当”,要搞清楚这个问题,我们先来看一 ...

  4. Spring-----注解开发和Spring测试单元

    一.注解开发 导入jar包;spring-aop-xxx.jar 导入约束:(在官方文档xsd-configuration.html可找) <beans xmlns="http://w ...

  5. 使用junit进行Spring测试

    这几天在做SpringMVC的项目,现在总结一下在测试的时候碰到的一些问题. 以前做项目,是在较新的MyEclipse(2013)上面进行Maven开发,pom.xml 文件是直接复制的,做测试的时候 ...

  6. Spring测试框架JUnit4.4 还蛮详细的

    TestContext 可以运行在 JUnit 3.8.JUnit 4.4.TestNG 等测试框架下. Spring的版本2.5+JUnit4.4+log4j1.2.12 @RunWith(Spri ...

  7. spring 测试类test测试方法

    实例掩码地址为:孔浩组织结构设计 web.xml配置文件: <!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 --> <context-param ...

  8. spring测试框架的使用

    junit的使用 1.加入 junit jar包 <dependency> <groupId>junit</groupId> <artifactId>j ...

  9. spring测试实例

    我们以前要进行单元测试,必须先得到ApplicationContext对象,再通过它得到业务对象,非常麻烦,重复代码也多.基于spring3的单元测试很好的解决了这个问题 基于spring3的单元测试 ...

随机推荐

  1. laravel5 MAC is invalid

    如果本机的环境更换过,项目中用来加密Crypt组件中的参数会变更. 如果出现这个问题,得更换数据库中加密后的变量 stackoverflow上找到的解决方法都是 composer dump-autol ...

  2. spring Bean的三种注入方式

    1.构造函数注入: 构造函数的注入方式分为很多种 (1)普通构造函数,空参数的构造函数 <bean id="exampleBean" class="examples ...

  3. 打开myeclipse2014的包资源管理器

    网上查到的方法不太适用于myeclipse2014,我就自己试了一下下 结果是:windows->show view->general->project package 结果: 希望 ...

  4. C++把引用作为返回值

    当返回一个引用时,要注意被引用的对象不能超出作用域.所以返回一个对局部变量的引用是不合法的,但是,可以返回一个对静态变量的引用. int& func() { int q; //! return ...

  5. 用PhotoSwipe制作相册,手势可放大

    1.引入css和js <link href="css/photoswipee.css" rel="stylesheet" type="text/ ...

  6. Java常用术语及区别

    Java中总有几个术语,平时说的多,但是还是让人有点摸不着头脑,今天就来解析一下他们的区别: l JDK:Java development toolkit,是 Java 语言的软件开发工具包(SDK) ...

  7. @Autowired与 @Resource

    @Autowired, @Resource 1.注解类型: Autowired可用于构造器.属性.方法.注解 @Target({ElementType.CONSTRUCTOR, ElementType ...

  8. directive(指令里的)的compile,pre-link,post-link,link,transclude

    The nitty-gritty of compile and link functions inside AngularJS directives  The nitty-gritty of comp ...

  9. webAppRootKey

    web.xml中webAppRootKey ------------------------------------------------------------------------------ ...

  10. Python朝花夕拾

    Q1:HTTP Error 403: Forbidden python中经常使用urllib2.urlopen函数提取网页源码,但是有些时候这个函数返回的却是:HTTP Error 403: Forb ...