📘 Premium Read: Access my best content on
Medium member-only articles
— deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed.
Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount):
Explore My Udemy Courses
— Learn through real-time, project-based development.
Testing is an essential aspect of software development. With Spring Boot, ensuring the reliability and robustness of our applications becomes a breeze, thanks to its powerful testing capabilities. It offers a wide range of tools, from unit to integration testing, seamlessly integrated for maximum efficiency. Whether you're new to testing in Spring Boot or just want to validate your knowledge, this MCQ guide is the perfect place to start. Let's dive in!
1. Which annotation is used for Integration testing in Spring Boot application?
a) @TestSearch
b) @SpringBootTest
c) @TestBoot
d) @RunTest
Answer:
b) @SpringBootTest
Explanation:
The @SpringBootTest annotation is used Integration testing in Spring Boot application.
2. Which class in Spring Boot provides methods to test web layers?
a) WebLayerTest
b) WebMvcTest
c) WebTestClient
d) MvcTester
Answer:
b) WebMvcTest
Explanation:
The WebMvcTest class in Spring Boot provides methods to test the web layers, including controllers.
3. How do you mock a bean for a Spring Boot test?
a) @Mock
b) @MockBean
c) @FakeBean
d) @InjectMock
Answer:
b) @MockBean
Explanation:
@MockBean is used to add mock objects to the Spring application context. The mock will replace any existing bean of the same type in the application context.
4. Which annotation is used for testing a specific layer or slice of the application?
a) @SpringBootLayerTest
b) @SpringBootSliceTest
c) @SliceTest
d) @LayerTest
Answer:
b) @SpringBootSliceTest
Explanation:
Spring Boot doesn’t have an annotation named @SpringBootSliceTest. However, "slice tests" refer to tests like @WebMvcTest, @DataJpaTest, etc., that focus on testing a specific layer of the application.
5. To test a JPA layer in isolation, which annotation should you use?
a) @JpaTest
b) @DatabaseTest
c) @DataJpaTest
d) @RepositoryTest
Answer:
c) @DataJpaTest
Explanation:
@DataJpaTest is used for testing JPA components in isolation.
6. Which tool in Spring Boot is used for testing RESTful Web Services?
a) RestTestClient
b) WebTestClient
c) RestControllerTest
d) WebMvcRestTest
Answer:
b) WebTestClient
Explanation:
WebTestClient is a tool provided by Spring Boot for testing RESTful Web Services.
7. Which assertion library is commonly used with Spring Boot tests?
a) JUnit
b) Mockito
c) AssertJ
d) TestNG
Answer:
c) AssertJ
Explanation:
While JUnit and Mockito are commonly used in testing, when it comes to assertion libraries specifically designed for better assertions, AssertJ is a popular choice with Spring Boot tests.
8. Which of the following is NOT a type of slice test in Spring Boot?
a) @WebMvcTest
b) @DataJpaTest
c) @ServiceTest
d) @JsonTest
Answer:
c) @ServiceTest
Explanation:
Spring Boot doesn't provide an out-of-the-box @ServiceTest annotation for slice testing. The other annotations mentioned are types of slice tests.
9. How do you test properties loaded from the application.properties file?
a) @Value
b) @PropertyTest
c) @ConfigTest
d) @TestProperty
Answer:
a) @Value
Explanation:
You can use the @Value annotation to inject properties loaded from the application.properties file in your tests.
10. Which annotation allows you to reset mocked beans after a test?
a) @DirtiesContext
b) @CleanContext
c) @ResetMock
d) @RefreshContext
Answer:
a) @DirtiesContext
Explanation:
The @DirtiesContext annotation can be used to reset the Spring context after a test, ensuring that mocked beans are reset.
11. Which interface helps to load a specific properties file during testing?
a) TestPropertyLoader
b) PropertiesLoader
c) TestPropertySource
d) PropertySourceTest
Answer:
c) TestPropertySource
Explanation:
The TestPropertySource interface is used to define property sources for your tests.
12. To mock server behavior for a RestTemplate, which class should you use?
a) MockRestServiceServer
b) RestTemplateMockServer
c) ServerMockRest
d) RestServerMock
Answer:
a) MockRestServiceServer
Explanation:
MockRestServiceServer is a class in Spring Boot used to mock server behavior for a RestTemplate.
Comments
Post a Comment
Leave Comment