1.pom.xml添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2.创建测试类
@SpringBootTest(classes = Demo2Application.class)
@RunWith(SpringRunner.class)
class Demo2ApplicationTests {
@Test
void test1() {
}
}
注意:如果不行,记得将测试class包名路径改为和启动类一样的路径包名