1. pom.xml ==> Depency

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency> <!-- Spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

2. BaseTest.java

package com.ctrip.arch.titanqconfig;

import junit.framework.TestCase;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class BaseTest extends TestCase { }

3. Sample

package com.ctrip.arch.titanqconfig.crypto;

import org.apache.logging.log4j.util.Strings;
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; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Soa2KeyService.class, DefaultDataSourceCrypto.class})
public class KeyServiceTester {
@Autowired
Soa2KeyService service; @Test
public void testGetKey() throws Exception {
String sslCode = "TT00000000000123";
String key = service.getKeyInfo(sslCode).getKey();
System.out.println("key=" + key);
assert(Strings.isNotBlank(key));
} }

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测试

    测试类添加两个注解 @RunWith(SpringJUnit4ClassRunner.class)和@ContextConfiguration(locations = "classpath: ...

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

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

  8. spring 测试类test测试方法

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

  9. spring测试框架的使用

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

  10. spring测试实例

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

随机推荐

  1. javascript form提交 不执行onsubmit事件解决方案

    转载自:https://www.cnblogs.com/lorgine/archive/2011/03/30/2000284.html 今天做项目过程中,需要用到javascript提交form到后台 ...

  2. 极速打包【shell版】

    同步发表至 http://avenwu.github.io/2014/12/16/fast_apk_release/ 前言 前阵子无意间看到美团的技术文章,一口气读了几篇java.android相关的 ...

  3. qualcomm wifi kernel beacon loss 日志记录

    记录一下高通对于beacon loss的处理的日志.方便后面再来分析. 04:17:13.397139 [04:17:13.383909] [000000A81699E7EC] [VosMC] wla ...

  4. PHP最全笔记(三)(值得收藏,不时翻看一下)

    /* [数组函数] *///统计计算count        计算数组中的单元数目或对象中的属性个数array_count_values  统计数组中所有的值出现的次数array_product    ...

  5. Mac: Alias[设置命令的别名]

    设置`.bash_profile` 1.打开终端`Terminal` 2.输入命令`cd ~`到用户主目录 $ cd ~ 3.生成一个新文件 $ touch .bash_profile 4.使用喜欢的 ...

  6. Android异步处理系列文章四篇之一使用Thread+Handler实现非UI线程更新UI界面

    目录: Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面Android异步处理二:使用AsyncTask异步更新UI界面Android异步处理三:Handler+L ...

  7. aws平台中为ec2实例添加双网卡

    亚马逊平台创建ec2实例时默认创建一个网卡primary网卡,主网卡是不能分离的. 在ec2服务控制台为ec2附加网卡. 平台资料中为正在使用的ec2添加网卡用到的操作系统是Amazon Linux ...

  8. ImageMagick、imagick和ghostscript三者的关联

    http://467754239.blog.51cto.com/4878013/1602518/ 一.功能概述 ImageMagick是第三方的图片处理软件,功能要比GD强大.建议两者都安装,并不冲突 ...

  9. 腾讯云Badjs镜像使用入门

    版权声明:本文由王少飞 原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/498929001487125840 来源:腾云阁  ...

  10. springboot JPA

    JPA(Java Persistence API)是Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据.他的出现主要是为了简化现有的持久 ...