Spring Cloud微服务项目搭建系列文章(四):Spring Boot单元测试

上一篇阿里云相关功能我们讲解了如何封装阿里云常用的功能,以及使用注解进行开关操作。

本文源码地址:

源码地址

正常的情况我们写完这个功能的时候是应该进行单元测试的,下面我们来讲解下如何进行单元测试

首先POM文件,导入测试相关的JAR包

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

然后新建单元测试的启动类

@SpringBootApplication
public class Run {
    public static void main(String[] args) {
        SpringApplication.run(Run.class, args);
    }
}

新建测试类

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Run.class)
@EnableAutoConfiguration
@EnableAliOss
public class RunTests {

    @Autowired
    private OssService ossService;

    @Test
    public void test() throws Exception {
        ossService.getToken("aa.sb3");
    }
}

在test目录的resources目录下新建application.yml,并配置相关配置

edu:
  aliyun:
    sms:
      product: 11
      domain: 22
      signName: xx
      endpoint: cn-beijing
      key: xx
      secret: xx
    oss:
      point: https://oss-cn-beijing.aliyuncs.com
      key: xx
      secret: xx
      buckName: xx
      baseurl: xx
      roleArn: xx
      roleSessionName: xx
      scratchCodeDir: xx
    vod:
      key: Lxx
      secret: qxx
      region: cn-shanghai
      uid: xx
      coverUrl: xx
      templateMode: xx

运行测试类即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值