• Spring 测试


    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));
        }
        
    }
  • 相关阅读:
    [Robot Framework] Robot Framework用Execute Javascript对XPath表示的元素执行scrollIntoView操作
    一台机器管理其他都装有kvm的实体机的虚拟机
    阿里云服务器问题
    开发族的跨域问题
    mysql不能连接的原因
    网络命令
    mysql5.7报错端口占用,服务起不来
    nagios的原理及server端跟client端安装配置全部过程
    查看CPU数量和核心数
    iptables的生产场景w
  • 原文地址:https://www.cnblogs.com/ylz8401/p/7383225.html
Copyright © 2020-2023  润新知