通常,以下内容足以测试应用程序上下文是否启动。
@RunWith(SpringRunner.class)@SpringBootTest(classes = Application.class)public class ApplicationTests { @Test public void contextLoads() { }}但是,如果您想直接测试
Application.main,也可以这样进行测试:
public class ApplicationTest { @Test public void test() { Application.main(new String[]{ "--spring.main.web-environment=false", "--spring.autoconfigure.exclude=blahblahblah", // Override any other environment properties according to your needs }); }}


