Annotation Type DataJpaTest
Tests persistence without the rest of the application: what Spring's
@DataJpaTest does.
The slice has the database, the entity manager and the module's repositories,
and none of its components, controllers or routes. A test injects the
EntityManager, the DataSource or a repository interface and calls it
directly. Components it needs too are named in includes(); a dependency of
theirs that the slice lacks fails the build.
The database is the one database() names, a fresh in-memory SQLite one by
default, whatever the module's settings say, so a persistence test never
touches a database that outlives it. The generated daos create their tables
in it, and migrations run as they do on start-up.
Each test method runs in a transaction that is rolled back when it returns,
as Spring's are, so one test's rows are not the next one's. @BeforeEach and
@AfterEach methods run outside it; rollback() set to false commits instead.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]TestConfigurationclasses to add, asBackendTest.classes().The database URL, ascn1.datasource.urltakes it.Class<?>[]Components and configurations of the application to wire into the slice, what Spring's@Importadds to one.The profile, asBackendTest.profile().String[]Settings for this test, askey=value, asBackendTest.properties().booleanWhether each test method's transaction is rolled back.
-
Element Details
-
includes
Class<?>[] includesComponents and configurations of the application to wire into the slice, what Spring's@Importadds to one.- Default:
{}
-
database
String databaseThe database URL, ascn1.datasource.urltakes it. An in-memory SQLite database by default, which is gone when the test run ends.- Default:
":memory:"
-
rollback
boolean rollbackWhether each test method's transaction is rolled back.- Default:
true
-
properties
-
profile
-
classes
-