@SpringBootTest

依赖:

        
            org.springframework.boot
            spring-boot-starter-test
            2.1.4.RELEASE
            test
        

代码:

package pers.wilson;

import com.App;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class UserTest {

    @Test
    public void userTest() {

        // ...
    }
}

你可能感兴趣的:(@SpringBootTest)