一、单元测试
1、修改pom文件,添加相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2、创建测试类与测试方法
- 给测试类添加测试启动器注解与Spring Boot单元测试注解
@RunWith(SpringRunner.class) //测试启动器,并加载Spring Boot测试注解
@SpringBootTest //标记Spring Boot单元测试,并加载applicationContext上下文环境
- 注入待测试类HelloWorld01Controller
- 创建测试方法contextLoad(),测试待测试类实例的方法
- 运行结果
- 修改测试方法
- 运行结果
二、Spring Boot热部署
1、在pom.xml文件里添加开发工具依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
2、热部署配置
- 单击[file]->[settings]菜单项,打开设置对话框,找到complier,勾选择build project automatically使用快速键
- 按组合键Ctrl + Shift + Alt + /打开Maintenance对话框
- 单击Registry选项,在Registry对话框里,勾选compiler.automake.allow.when.app.running,让程序在运行过程中也能自动编译
采用了热部署,修改了程序,不用重启项目,系统会在程序运行过程中自动编译,于是可以看到修改后程序的运行结果。