首页 > 编程语言 > 详细

基于spring-boot的测试桩设计-添加配置文件(properties)

时间:2019-09-15 10:31:39      阅读:103      评论:0      收藏:0      [点我收藏+]

编写测试时,有些内容可以放到配置文件中。

 

第一步:新增配置文件 conf.properties

技术分享图片

 

 技术分享图片

 

 第二步:编写配置文件类 MockConf

技术分享图片

 

 

 1 package mock.mockdemo.conf;
 2 
 3 import lombok.Data;
 4 import org.springframework.beans.factory.annotation.Value;
 5 import org.springframework.context.annotation.PropertySource;
 6 import org.springframework.stereotype.Component;
 7 
 8 
 9 @Data
10 @Component
11 @PropertySource("classpath:config/conf.properties")
12 public class MockConf {
13     @Value("${user_num}")
14     public String userNum;
15 }

第三步:添加接口和实现类

技术分享图片

接口:

技术分享图片

 

实现类:

 技术分享图片

 技术分享图片

 

 第四步:编写controller

技术分享图片

 

 

测试:

技术分享图片

 

 技术分享图片

 

 结果:可以正常获取到配置文件内容

 

 

 源码地址:

https://github.com/yuesest/mockdemo

基于spring-boot的测试桩设计-添加配置文件(properties)

原文:https://www.cnblogs.com/moonpool/p/11521109.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!