Springboot中的test
2017-12-06 11:12
330 查看
spring-boot-starter-test整合了spring-test和junit,简化了test,好用极了。直接贴代码讲解吧
1.maven配置:
这在创建Spring Initializr项目时,自带进来的test配置,也自动生成了test文件夹,文件夹下是一个test项目,自带了一个应用程序类**ApplicationTests:(@RunWith、@SpringBootTest两个标注标明了此类是测试启动类,@Test标注了测试方法)
2.我们直接在这个类里添加测试方法,像开发中引用service一样,在测试方法体里去调用就可以了:
3.运行测试
在方法体中右键,选择“Run testGetUser”,即可启动测试。IDEA窗口下方会出现测试窗口。
1.maven配置:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <!-- 表示开发的时候引入,发布的时候不会加载此包 --> <scope>test</scope> </dependency>
这在创建Spring Initializr项目时,自带进来的test配置,也自动生成了test文件夹,文件夹下是一个test项目,自带了一个应用程序类**ApplicationTests:(@RunWith、@SpringBootTest两个标注标明了此类是测试启动类,@Test标注了测试方法)
@RunWith(SpringRunner.class) @SpringBootTest public class DemoApplicationTests { @Test public void contextLoads() { } }
2.我们直接在这个类里添加测试方法,像开发中引用service一样,在测试方法体里去调用就可以了:
3.运行测试
在方法体中右键,选择“Run testGetUser”,即可启动测试。IDEA窗口下方会出现测试窗口。
相关文章推荐
- Spring Boot的单元测试(Unit Test)
- Spring boot 学习笔记(04)—— 多环境配置(dev,test,pro)
- spring boot maven 略过 test
- org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method service() cannot be found on com.my.blog.springboot.thymeleaf.util.MethodTest type
- Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test java.lang.IllegalStateException
- JSONAssert & Spring Boot Test
- SpringBoot Test集成测试
- SpringBoot Test集成测试
- spring boot(24)-test测试
- SpringBoot+Junit Test
- Spring Boot Test 学习
- SpringBoot(Test)
- Spring Boot 单元测试之 @WebIntegrationTest
- spring-boot-maven-plugin 插件,关闭自动test
- maven打包springboot项目跳过test文件夹
- Spring Boot Unit Test
- Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(
- springboot Test 自动配置注解详单
- springboot test
- org.springframework.boot.test.SpringApplicationConfiguration;