What is the best way to test that a spring application context fails to start?

前端 未结 3 486
情书的邮戳
情书的邮戳 2021-01-13 19:01

I use the spring-boot-starter-web and spring-boot-starter-test.

Let\'s say I have a class for binding configuration properties:

@ConfigurationPropert         


        
3条回答
  •  醉梦人生
    2021-01-13 19:26

    I think the easiest way is:

    public class InvalidUrlTest {
    
        @Rule
        public DisableOnDebug testTimeout = new DisableOnDebug(new Timeout(5, TimeUnit.SECONDS));
        @Rule
        public ExpectedException expected = ExpectedException.none();
    
        @Test
        public void shouldFailOnStartIfUrlInvalid() {
            // configure ExpectedException
            expected.expect(...
    
            MyApplication.main("--dummy.url=123:456");
        }
    
    // other cases
    }
    

提交回复
热议问题