2V0-72-22 practice question 3 of 15

Which two statements are true regarding Spring and Spring Boot Testing? (Choose two.)

Full set: 79 questions
Answer options
A:

A. EasyMock is supported out of the box.

B:

B. @SpringBootTest or @SpringJUnitConfig can be used for creating an ApplicationContext.

Correct answer
C:

C. Mockito spy is not supported in Spring Boot testing by default.

D:

D. The spring-test dependency provides annotations such as @Mock and @MockBean.

E:

E. Integration and slice testing are both supported.

Correct answer
Correct Answer:
B. B. @SpringBootTest or @SpringJUnitConfig can be used for creating an ApplicationContext.; E. E. Integration and slice testing are both supported.
Explanation

The Spring testing framework provides comprehensive support for both unit and integration testing. Annotations like @SpringBootTest (from Spring Boot) and @SpringJUnitConfig (from Spring Framework) are used to bootstrap a Spring ApplicationContext for tests. Spring Boot enhances this by supporting "slice testing" with annotations like @WebMvcTest or @DataJpaTest, which load only a specific part of the application context. This allows for faster, more focused integration tests alongside full application tests.

Why Incorrect

A. The spring-boot-starter-test dependency includes Mockito for mocking, not EasyMock. EasyMock would need to be added as a separate dependency.
C. Mockito is included by default and fully supports spies. Spring Boot provides @SpyBean to add Mockito spies to the application context.
D. @Mock is a core Mockito annotation. @MockBean is provided by the spring-boot-test module, not the core spring-test dependency.

References

1. Spring Boot Reference Documentation, Version 3.2.1. Section 5.1, "Test Scope Dependencies". This section lists the libraries provided by spring-boot-starter-test, which includes Mockito. Available at: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.test-scope-dependencies

2. Spring Boot Reference Documentation, Version 3.2.1. Section 5.4, "Testing Spring Applications". This section describes using @SpringBootTest to load a complete ApplicationContext. Available at: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications

3. Spring Boot Reference Documentation, Version 3.2.1. Section 5.6, "Testing Application Slices". This section explains the concept of slice tests and lists annotations like @WebMvcTest. Available at: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.slices

4. Spring Framework Reference Documentation, Version 6.1.2. Section 14.5.3, "Spring JUnit Jupiter Annotations". This section details the @SpringJUnitConfig composed annotation for creating an ApplicationContext. Available at: https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#spring-testing-annotations-junit-jupiter

Scroll to Top