@DirtiesContext @Test void testProcessWhichDirtiesAppCtx() { // some logic that results in the Spring container being dirtied } Dirty the context after the current test method.
Question 2
Which two statements are true regarding @DataJpaTest? (Choose two.)
Options:
A.
TestEntityManager provides all methods that are provided by EntityManager and more.
B.
If an embedded database is on the classpath, it will be used to configure a DataSource by default.
C.
It can be used for testing both JPA components and NoSQL components.
D.
It auto-configures a TestEntityManager bean.
E.
It can be used for testing JdbcTemplate.
Answer:
B, D
Explanation:
B. If an embedded database is on the classpath, it will be used to configure a DataSource by default.
This is true because the @DataJpaTest annotation enables auto-configuration of an embedded database if one is available on the classpath, such as H2, HSQLDB, or Derby. This allows the test to run with a temporary and isolated database that can be configured with test data.
D. It auto-configures a TestEntityManager bean.
This is true because the @DataJpaTest annotation provides a TestEntityManager bean that can be used to perform common JPA operations in the test. The TestEntityManager is an alternative to the standard EntityManager that provides some convenience methods and exception translation.