Spring Framework Quality Control & Assurance 3 — Questions and Answers
Question 1: Which tool integrated with Spring Boot Actuator provides health checks that can be used for quality assurance in production?
- Spring Security
- Spring Actuator HealthIndicator (Correct answer)
- Spring Batch
- Spring Cloud Config
Correct answer: Spring Actuator HealthIndicator
Spring Boot Actuator's HealthIndicator interface allows components to report their health status via the /actuator/health endpoint.
Question 2: What is the role of Testcontainers when used with Spring Boot tests?
- Provides mock implementations of Spring beans
- Starts real Docker containers (e.g., databases) during integration tests (Correct answer)
- Generates test data automatically
- Replaces the embedded Tomcat with a containerized server
Correct answer: Starts real Docker containers (e.g., databases) during integration tests
Testcontainers starts and manages real Docker containers for services like PostgreSQL or Redis during integration test execution.
Question 3: In Spring, which annotation marks a method to run before each test method in a JUnit 5 test class?
- @Before
- @BeforeEach (Correct answer)
- @Setup
- @Init
Correct answer: @BeforeEach
JUnit 5 uses @BeforeEach (not JUnit 4's @Before) to annotate setup methods that run before each individual test.
Question 4: Which Spring framework feature allows you to verify that a method was called on a @MockBean a specific number of times?
- Verify API from Mockito via Mockito.verify() (Correct answer)
- Spring's @AssertCalled annotation
- JUnit's assertInvocations() method
- MockMvc's .andExpect(invocations(1))
Correct answer: Verify API from Mockito via Mockito.verify()
Mockito.verify() combined with times() allows assertions on how many times a method was called on a mock or spy bean.
Question 5: What does the @Transactional annotation do when applied to a Spring test method?
- Commits the transaction after each test to persist data
- Rolls back the transaction after each test by default (Correct answer)
- Disables transaction management for that test
- Starts a new distributed transaction across services
Correct answer: Rolls back the transaction after each test by default
When @Transactional is applied to a Spring test, the transaction is rolled back after each test method by default, keeping the database clean.
Question 6: Which Spring Boot Actuator metric can help QA teams detect slow database queries in production?
- spring.datasource.active
- spring.jpa.query.time
- spring.datasource.hikari.pending-threads (Correct answer)
- jdbc.connections.max
Correct answer: spring.datasource.hikari.pending-threads
The HikariCP metric for pending threads indicates connection pool exhaustion, which can signal slow queries blocking other requests.
Question 7: What is the purpose of the @ParameterizedTest annotation in JUnit 5 when writing Spring tests?
- Injects Spring beans as test method parameters
- Runs the same test method multiple times with different input values (Correct answer)
- Marks a test as requiring a parameterized Spring context
- Configures test parameters from application.properties
Correct answer: Runs the same test method multiple times with different input values
@ParameterizedTest enables running the same test with multiple data sets, improving coverage without duplicating test methods.
Which tool integrated with Spring Boot Actuator provides health checks that can be used for quality assurance in production?