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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM