码迷,mamicode.com
首页 > 编程语言 > 详细

Spring 测试

时间:2017-08-17 18:40:14      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:ota   ons   ack   default   pid   context   factory   titan   unit   

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

标签:ota   ons   ack   default   pid   context   factory   titan   unit   

原文地址:http://www.cnblogs.com/ylz8401/p/7383225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!