Spring Cloud Quality Control & Assurance 5 — Questions and Answers
Question 1: Which Spring Boot test annotation should you use to test only the web layer (controllers) without loading the full application context?
- @WebMvcTest (Correct answer)
- @SpringBootTest
- @DataWebTest
- @ControllerTest
Correct answer: @WebMvcTest
@WebMvcTest loads only MVC components (controllers, filters, converters) and auto-configures MockMvc without service or repository beans.
Question 2: How does Spring Cloud Sleuth integrate with Logback to include trace information in log output?
- By automatically adding traceId and spanId to the MDC (Mapped Diagnostic Context) (Correct answer)
- By appending trace IDs to every log message as a suffix
- By replacing the log pattern with a Sleuth-specific format
- By writing traces to a separate log file from application logs
Correct answer: By automatically adding traceId and spanId to the MDC (Mapped Diagnostic Context)
Sleuth populates MDC keys (traceId, spanId, exportable) so any Logback pattern using %X{traceId} automatically includes distributed trace context.
Question 3: What is the role of the Spring Cloud Contract Stub Runner in consumer-side tests?
- It downloads and starts WireMock stubs published by the producer for use in consumer tests (Correct answer)
- It generates stubs on the fly from consumer test code
- It validates that consumer calls match the producer's OpenAPI spec
- It records real HTTP traffic and converts it to stubs
Correct answer: It downloads and starts WireMock stubs published by the producer for use in consumer tests
Stub Runner fetches the published stubs JAR from a local or remote Maven repository and launches WireMock with those stubs, simulating the producer.
Question 4: Which Resilience4j module provides time-limited execution for Spring Cloud service calls to prevent thread starvation?
- TimeLimiter (Correct answer)
- Bulkhead
- RateLimiter
- CircuitBreaker
Correct answer: TimeLimiter
TimeLimiter cancels a call that exceeds a configured duration, preventing threads from blocking indefinitely on slow downstream services.
Question 5: When writing a Spring Cloud Gateway integration test, which test utility allows you to make HTTP requests to the gateway and assert responses?
- WebTestClient (Correct answer)
- MockMvc
- TestRestTemplate
- RestAssured
Correct answer: WebTestClient
WebTestClient is the reactive-compatible HTTP client used in Spring WebFlux and Spring Cloud Gateway tests for making assertions on reactive HTTP responses.
Question 6: What does the spring.cloud.config.fail-fast=true property do when a Config Server is unavailable at startup?
- Causes the application to fail immediately instead of starting with default values (Correct answer)
- Enables fast failover to a secondary Config Server
- Disables the retry mechanism for config fetching
- Logs a warning and continues startup with cached values
Correct answer: Causes the application to fail immediately instead of starting with default values
With fail-fast=true, the application throws an exception and refuses to start if it cannot connect to the Config Server, preventing misconfigured deployments.
Question 7: Which Spring Boot Actuator feature helps QA teams monitor the health of downstream dependencies in a Spring Cloud application?
- Composite health indicators that aggregate status of all dependencies (Correct answer)
- Spring Cloud Health Gateway filter
- Resilience4j health dashboard endpoint
- Spring Cloud Bus health broadcast
Correct answer: Composite health indicators that aggregate status of all dependencies
Spring Boot Actuator supports composite health indicators that roll up the health of databases, message brokers, and custom services into a single /actuator/health response.
Which Spring Boot test annotation should you use to test only the web layer (controllers) without loading the full application context?