Bird
0
0

Which of the following is the correct way to use @SpringBootTest to start the web environment on a random port?

easy📝 Syntax Q12 of 15
Spring Boot - Testing Spring Boot Applications
Which of the following is the correct way to use @SpringBootTest to start the web environment on a random port?
A@SpringBootTest(webEnv = RANDOM_PORT)
B@SpringBootTest(webEnvironment = "random")
C@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
D@SpringBootTest(port = RANDOM_PORT)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct attribute name and value

    The attribute to set the web environment is webEnvironment, and the enum value for random port is WebEnvironment.RANDOM_PORT.
  2. Step 2: Check syntax correctness

    @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) uses the correct attribute and enum syntax. Other options use incorrect attribute names or string values.
  3. Final Answer:

    @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -> Option C
  4. Quick Check:

    Correct attribute and enum = @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) [OK]
Quick Trick: Use webEnvironment = WebEnvironment.RANDOM_PORT exactly [OK]
Common Mistakes:
  • Using wrong attribute name like webEnv
  • Passing string instead of enum
  • Trying to set port directly in annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes