You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to access a global EntityManager instance from @nested classes I get the following exception: java.lang.IllegalArgumentException: JPA test must have either EntityManagerFactory or EntityManager field annotated with @PersistenceUnit, respectively @PersistenceContext
My class looks like this:
@ExtendWith(JpaUnit.class)
class NestedTest {
@PersistenceContext(unitName = "my-test-unit")
private EntityManager entityManager;
@Nested
@DisplayName("Given an empty test table")
class GivenAnEmptyTestTable {
@Test
@DisplayName("Then the size sould be zero")
void thenTheSizeShouldBeZero() {
List<Test> list = entityManager
.createQuery("select t from Test t", Test.class)
.getResultList();
assertEquals(list.size(), 0);
}
@Nested
@DisplayName("When a row is inserted")
class WhenARowIsInserted {
@BeforeEach
@Transactional(TransactionMode.COMMIT)
void setUp() {
Test t = new Test(1, 2, 3);
entityManager.persist(t);
}
@Test
@DisplayName("Then the size should be one")
void thenTheSizeShouldBeOne() {
List<Test> list = entityManager
.createQuery("select t from Test t", Test.class)
.getResultList();
assertEquals(list.size(), 0);
}
}
}
}
Is it somehow possible to keep the entityManager instance in the nested tests?
The text was updated successfully, but these errors were encountered:
When I try to access a global EntityManager instance from @nested classes I get the following exception:
java.lang.IllegalArgumentException: JPA test must have either EntityManagerFactory or EntityManager field annotated with @PersistenceUnit, respectively @PersistenceContext
My class looks like this:
Is it somehow possible to keep the entityManager instance in the nested tests?
The text was updated successfully, but these errors were encountered: