1、设置使用环境 - MySQL数据库环境,并测试
(1)在全局配置文件application.properties里配置使用环境
(2)打开测试类,编写测试方法
package net.tjl.lesson05;
import net.tjl.lesson05.config.DatabaseConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ProfileDemo02ApplicationTests {
@Autowired//注入数据库配置实体
private DatabaseConfig databaseConfig;
@Test
void contextLoads() {
//调用数据库配置实体的方法
databaseConfig.connector();
}
}
(3)运行测试方法,查看结果
运行测试方法contextLoads()
2、设置使用环境 - Sybase数据库环境,并测试
(1)在全局配置文件application.properties里配置使用环境
(2)打开测试类,编写测试方法
package net.tjl.lesson05;
import net.tjl.lesson05.config.DatabaseConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ProfileDemo02ApplicationTests {
@Autowired//注入数据库配置实体
private DatabaseConfig databaseConfig;
@Test
void contextLoads() {
//调用数据库配置实体的方法
databaseConfig.connector();
}
}
(3)运行测试方法,查看结果
运行测试方法contextLoads()
3、测试长整型随机数my.long
注入配置文件里的属性
输出配置文件里的属性
package net.tjl.lesson05;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class RandomSetDemoApplicationTests {
// 注入配置文件里的属性
@Value("${my.long}")
private String number;
@Test
void contextLoads() {
// 输出配置文件里的属性
System.out.println(number);
}
}
反复运行测试方法contextLoads(),查看结果
4、测试随机UUID值my.uuid
注入配置文件里的属性
输出配置文件里的属性
package net.tjl.lesson05;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class RandomSetDemoApplicationTests {
// 注入配置文件里的属性
@Value("${my.uuid}")
private String number;
@Test
void contextLoads() {
// 输出配置文件里的属性
System.out.println(number);
}
}
反复运行测试方法contextLoads(),查看结果
5、测试小于10的随机整数my.number.less
package net.tjl.lesson05;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class RandomSetDemoApplicationTests {
// 注入配置文件里的属性
@Value("${my.number.less}")
private String number;
@Test
void contextLoads() {
// 输出配置文件里的属性
System.out.println(number);
}
}
反复运行测试方法contextLoads(),查看结果
6、测试1024至65535之间的随机整数my.number.range
package net.tjl.lesson05;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class RandomSetDemoApplicationTests {
// 注入配置文件里的属性
@Value("${my.number.range}")
private String number;
@Test
void contextLoads() {
// 输出配置文件里的属性
System.out.println(number);
}
}
反复运行测试方法contextLoads(),查看结果