上一篇阿里云相关功能我们讲解了如何封装阿里云常用的功能,以及使用注解进行开关操作。
本文源码地址:
正常的情况我们写完这个功能的时候是应该进行单元测试的,下面我们来讲解下如何进行单元测试
首先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
运行测试类即可