Spring Certified Professional 2023 · Free Practice Question Medium

Question 6

When using the @SpringBootTest annotation with the attribute webEnvironment set to RANDOM_PORT or DEFINED_PORT, which class is created and configured accordingly?

  • A

    TestPropertySource

  • B

    TestRestTemplate

  • C

    MockMvc

  • D

    SpringApplication

Reveal correct answer

Correct answer: B

Explanation

The correct answer is TestRestTemplate.


When using @SpringBootTest with webEnvironment set to RANDOM_PORT or DEFINED_PORT, a TestRestTemplate is created and configured with the appropriate port for the test environment.


This allows for easy testing of HTTP requests and responses in a Spring Boot application.


TestPropertySource is used to define properties for the test environment, SpringApplication is used to configure and bootstrap the application context, and MockMvc is used for testing Spring MVC controllers.


https://docs.spring.io/spring-boot/docs/2.5.2/api/org/springframework/boot/test/web/client/TestRestTemplate.html

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need