Bird
0
0

You want to write an integration test that loads the full Spring Boot context but disables the web server startup to speed up tests. Which @SpringBootTest configuration should you use?

hard📝 Application Q15 of 15
Spring Boot - Testing Spring Boot Applications
You want to write an integration test that loads the full Spring Boot context but disables the web server startup to speed up tests. Which @SpringBootTest configuration should you use?
A@SpringBootTest(webEnvironment = WebEnvironment.NONE)
B@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
C@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
D@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
Step-by-Step Solution
Solution:
  1. Step 1: Understand webEnvironment options

    WebEnvironment.NONE disables web server startup but loads full context. MOCK uses mock servlet environment, RANDOM_PORT and DEFINED_PORT start real servers.
  2. Step 2: Choose option that disables web server

    To speed up tests without web server, use WebEnvironment.NONE.
  3. Final Answer:

    @SpringBootTest(webEnvironment = WebEnvironment.NONE) -> Option A
  4. Quick Check:

    Disable web server with WebEnvironment.NONE [OK]
Quick Trick: Use WebEnvironment.NONE to skip web server startup [OK]
Common Mistakes:
  • Using MOCK which still sets up servlet environment
  • Starting real server with RANDOM_PORT or DEFINED_PORT
  • Confusing NONE with MOCK

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes