@SpringBootTest — Concept Check
Questions on @SpringBootTest. @SpringBootTest loads the full application context for integration tests; use webEnvironment=RANDOM_PORT for tests that exercise the real HTTP stack.
Questions in this quiz
8 questions on @SpringBootTest — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to test the full HTTP stack including filters and security. Which @SpringBootTest webEnvironment should they use?
- ADEFINED_PORT
- BRANDOM_PORT
- CNONE
- DMOCK
2.You notice your integration tests are slow. Which annotation could speed them up by loading only the MVC layer?
- A@JsonTest
- B@WebMvcTest
- C@SpringBootTest
- D@DataJpaTest
3.A test using @SpringBootTest(webEnvironment=MOCK) fails to connect to a real server. Why?
- ANONE doesn't start a server
- BMOCK doesn't start a real server
- CTestRestTemplate isn't configured
- DRANDOM_PORT is needed
4.Which test slice annotation is best for testing JPA repository queries?
- A@DataJpaTest
- B@WebMvcTest
- C@JsonTest
- D@WebFluxTest
5.A developer uses @SpringBootTest with webEnvironment=NONE but needs to test HTTP requests. What's wrong?
- ANONE doesn't start a server
- BRANDOM_PORT is needed
- CDEFINED_PORT is required
- DMOCK is better for HTTP
6.Which annotation allows testing JSON serialization independently?
- A@WebMvcTest
- B@JsonTest
- C@DataJpaTest
- D@SpringBootTest
7.A developer mistakenly expects @WebMvcTest to load service beans. What should they do?
- AUse @DataJpaTest
- BUse @MockBean for services
- CSwitch to @SpringBootTest
- DAdd @SpyBean for services
8.Why might a developer choose @SpringBootTest over test slice annotations?
- AFor faster test execution
- BTo test the full application context
- CTo avoid mocking beans
- DTo test only the MVC layer