配置文件里的random
随机数- 添加application.yml配置文件内容
randomtest:
id: ${random.int} #随机数int
name: ${random.uuid} #随机uuid
age: ${random.int(4,9)} #随机数4到9
time: ${random.long} #随机数long值
name2: hello${random.int} #组合字符串
- 编写测试用例
@SpringBootTest
class SpringbootSsmpdemoApplicationTests {
@Value("${randomtest.id}")
private int id;
@Value("${randomtest.name}")
private String name;
@Value("${randomtest.age}")
private int age;
@Value("${randomtest.time}")
private long time;
@Value("${randomtest.name2}")
private String name2;
@Test
void contextLoads() {
System.out.println(id);
System.out.println(name);
System.out.println(age);
System.out.println(time);
System.out.println(name2);
}
}
- 执行



