Spring Boot超简单的测试类demo

111111  


Spring Boot结合Junit的简单测试类demo

1.引入依赖

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

2.编写测试类

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("--------------------------------------------------");
    }

}

3.

java.lang.IllegalStateException Unable to find a @SpringBootConfiguration错误解决方案

在进行单元测试时我太懒了,随便建了个test包就进行测试,导致出现这个问题
解决方案:
将包名改为与其他分支一样的路径。就可以了!
如下图:

原文地址:https://www.cnblogs.com/nextgg/p/15409490.html