Skip to content

TestEntityManager can't be configured in @BeforeAll method in test class with @TestInstance(PER_CLASS) in JUnit Jupiter [SPR-16550] #21093

Closed
@spring-projects-issues

Description

@spring-projects-issues

Aleksandr opened SPR-16550 and commented

When trying to autowire Spring Boot's TestEntityManager in method annotated as @BeforeAll, the following exception is thrown:

java.lang.IllegalStateException: No transactional EntityManager found

Other beans are autowired into this method without problems.

The case is following - since I have one test class instance for all tests in it, and they require the same prepopulated DB, why not fill the DB once after test class instantiation?

Sample project is referenced in the issue.


Reference URL: https://gitlab.com/AleksandrSl/spring-sandbox/blob/junit-5-security/src/test/kotlin/pro/parseq/springsandbox/entities/UserItemsSecurityTests.kt

Issue Links:

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions