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

前端 未结 3 485
情书的邮戳
情书的邮戳 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:13

    Why is that an integration test to begin with? Why are you starting a full blown Spring Boot app for that?

    This looks like unit testing to me. That being said, you have several options:

    • Don't add @IntegrationTest and Spring Boot will not start a web server to begin with (use @PropertySource to pass value to your test but it feels wrong to pass an invalid value to your whole test class)
    • You can use spring.main.web-environment=false to disable the web server (but that's silly given the point above)
    • Write a unit test that process that DummyProperties of yours. You don't even need to start a Spring Boot application for that. Look at our own test suite

    I'd definitely go with the last one. Maybe you have a good reason to have an integration test for that?

提交回复
热议问题