Spring Boot超简单的测试类demo

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进行测试。
在这里插入图片描述

猜你喜欢

转载自www.cnblogs.com/6b7b5fc3/p/12909995.html