I have an @SpringBootTest JUnit 5 integration test that has an @TestExecutionListener registered, which implements AbstractTestExecutionListener and overrides afterTestClass(...). The listener is supposed to connect to my in-memory test DB and to reset indexes. It works fine.
As soon as I add @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD) to the test class, however, it fails in the listener's afterTestClass method with an error message:
WARN o.s.test.context.TestContextManager - Caught exception while invoking 'afterTestClass' callback on TestExecutionListener [...] for test class [...]
java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-1) has been closed.
I have tried to run the test with TRACE logging for all Spring classes, but can't really see why this happens when comparing the output for both, with and without the annotation; the ApplicationContext isn't closed until after the error is logged.
I would expect this to fail if the context was removed after each test method (and thus potentially before the listener is executed), but not with the context being removed before a test method runs. (The listener isn't considered a test method, is it?)
Comment From: wilkinsona
Can you share a small sample that reproduces the behavior you've described?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.