I am using h2 embedded database which is defined like that:
<jdbc:embedded-database id="embeddedDatasource" type="h2"/>
And I have two tests:
@RunWith(SpringJunit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("classpath:h2-context.xml")
class Test1 {...}
@RunWith(SpringJunit4ClassRunner.class)
@ContextConfiguration("classpath:h2-context.xml")
class Test2 {...}
After all tests execution I do see in the log:
* Closing org.springframework.context.support.GenericApplicationContext
* Closing org.springframework.web.context.support.GenericWebApplicationContext
* Closing JPA EntitiManagerFactory for Persistance unit ...
* Closing JPA EntitiManagerFactory for Persistance unit ...
So, the entity manager is closed for each context after all tests execution. I know that spring caches context files, so I guess h2 bean is shared across two tests.
The problem is: sometimes I get weird exception like:
H2EmbeddedDatabaseConfigurer: Could not shutdown embedded database
jrg.h2.jdbc.JDBCSQLException: The database has been closed [90098-179]
How could I fix that?
This is what I've found so far: Spring’s embedded H2 datasource and DB_CLOSE_ON_EXIT
spring-jdbc
(i.e., Spring Framework in general) are you using? – Galloot