springboottest 指定启动类

Spring Boot 测试时可以使用 @SpringBootTest 注解来指定启动类。具体使用方法如下:

  • 在启动类上添加 @SpringBootTest 注解。
  • @SpringBootTest
    @RunWith(SpringRunner.class)
    public class YourApplicationTests {
        //...
    
  • 也可以通过 classes 属性指定启动类:
  • @SpringBootTest(classes = {YourApplication.class})
    @RunWith(SpringRunner.class)
    public class YourApplicationTests {
        //...
    

    在测试类里面可以使用 spring-test 模块提供的一系列注解来进行针对 spring-boot 的测试。

  •