Spring Boot超简单的测试类demo

夙愿已清 提交于 2020-10-03 08:55:53

1 概述

Spring Boot结合Junit的简单测试类demo,流程是先引入依赖,接着编写测试类测试运行即可。

2 依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-test</artifactId>
	<scope>test</scope>
</dependency>

3 编写测试类

在test/java下编写测试类,默认带一个叫项目名+Tests的测试类:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class ApplicationTests {

    @Test
    public void contextLoads() {
        System.out.println("--------------------------------------------------");
    }

}

4 测试

点击方法或类左边的按钮或者Ctrl+Shift+F10进行测试。 在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!