Package org.dbunit.database
Class InMemoryDatabaseConnection
java.lang.Object
org.dbunit.database.InMemoryDatabaseConnection
Test utility that creates an isolated H2 in-memory
IDatabaseConnection
for unit tests that need a real connection without the full
DatabaseEnvironment bootstrap.
Each call to create() or create(String) produces a
connection to a distinct in-memory H2 database, ensuring test isolation.
The caller is responsible for closing the returned connection.
- Since:
- 3.2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic IDatabaseConnectioncreate()Creates anIDatabaseConnectionbacked by a fresh H2 in-memory database.static IDatabaseConnectionCreates anIDatabaseConnectionbacked by a fresh H2 in-memory database using the given schema name.
-
Method Details
-
create
Creates anIDatabaseConnectionbacked by a fresh H2 in-memory database.- Returns:
- a new connection; caller is responsible for closing it
- Throws:
Exception- if the connection cannot be created
-
create
Creates anIDatabaseConnectionbacked by a fresh H2 in-memory database using the given schema name.- Parameters:
schema- the schema name- Returns:
- a new connection; caller is responsible for closing it
- Throws:
Exception- if the connection cannot be created
-