Spring Framework Research & Evidence-Based Practice 2 — Questions and Answers
Question 1: Which Spring testing annotation loads a full application context while allowing bean override for isolated integration tests?
- @WebMvcTest
- @SpringBootTest (Correct answer)
- @DataJpaTest
- @ContextConfiguration
Correct answer: @SpringBootTest
@SpringBootTest loads the complete application context and supports bean overrides via @MockBean or @SpyBean for controlled integration testing.
Question 2: When benchmarking a Spring Boot REST endpoint, which tool is most commonly recommended in the Spring community for HTTP load testing?
- Gatling or JMeter (Correct answer)
- Selenium WebDriver
- JUnit Parameterized Tests
- Mockito verify()
Correct answer: Gatling or JMeter
Gatling and JMeter are the evidence-based choices for HTTP load testing Spring REST endpoints, providing throughput and latency metrics.
Question 3: What does the Spring Framework's official documentation recommend as the primary source of truth for verifying bean lifecycle behavior?
- Stack Overflow answers
- Spring reference docs and Javadoc (Correct answer)
- Third-party blog posts
- GitHub issue comments
Correct answer: Spring reference docs and Javadoc
The Spring reference documentation and official Javadoc are the authoritative, evidence-based sources for understanding bean lifecycle guarantees.
Question 4: Which Spring project provides the Micrometer integration that enables evidence-based performance monitoring through metrics collection?
- Spring Security
- Spring Batch
- Spring Boot Actuator (Correct answer)
- Spring Data REST
Correct answer: Spring Boot Actuator
Spring Boot Actuator integrates Micrometer to expose metrics endpoints, enabling data-driven performance monitoring and observability.
Question 5: A developer wants to isolate only the JPA layer during testing. Which slice test annotation does Spring Boot provide for this?
- @SpringBootTest(webEnvironment=NONE)
- @DataJpaTest (Correct answer)
- @JsonTest
- @RestClientTest
Correct answer: @DataJpaTest
@DataJpaTest configures only JPA-related beans and an in-memory database, providing a focused, evidence-based slice test for the persistence layer.
Question 6: Which approach does Spring's own test documentation recommend for verifying that a @Transactional method rolls back correctly in tests?
- Use @Commit in the test class
- Assert via @Rollback(false)
- Rely on default @Transactional test rollback behavior (Correct answer)
- Use Thread.sleep() after the call
Correct answer: Rely on default @Transactional test rollback behavior
By default, Spring's TestContext Framework rolls back transactions after each test method, which is the recommended approach for verifying transactional behavior without polluting the database.
Question 7: What is the evidence-based best practice when interpreting JVM warm-up effects in Spring application startup benchmarks?
- Measure only the first cold-start run
- Discard early iterations and average steady-state results (Correct answer)
- Use wall-clock time from the OS boot
- Disable JIT compilation for fair comparison
Correct answer: Discard early iterations and average steady-state results
JVM JIT compilation skews early runs, so benchmarks should discard warm-up iterations and report steady-state averages for accurate Spring application performance data.
Which Spring testing annotation loads a full application context while allowing bean override for isolated integration tests?