一、获取config.properties中的数据
1. 在resources目录下配置config.properties文件
# 人才库入职
talentPool.fullSpell = autotest
talentPool.idCardEndDate = 2020-04-29
talentPool.baseRegionCode = MRYXHB
2. 添加注解:在LopApplication添加注解
@PropertySource("classpath:config.properties")
public class LopApplication {
public static void main(String[] args) {
SpringApplication.run(LopApplication.class, args);
}
}
3. 在用例中引用数据
/ 调用录用员工接口
EmployNormalBody body = new EmployNormalBody();
body.setLabourName(environment.getProperty("talentPool.labourName"));
body.setBaseStationCode(environment.getProperty("talentPool.baseStationCode"));
Response res = context.getBean(EmployNormal.class).setBody(body).request();
Assert.assertEquals(res.getStatusCode(), 200, "人才库-录用人员,返回状态码!=200");
二、读取config.properties乱码问题
1. 当配置文件为中文的时候,会出现乱码的问题
image
2. 解决方式:在application类中的注解后添加encoding = "utf-8"
@PropertySource(value = "classpath:config.properties", encoding = "utf-8")
public class LopApplication {
...
}