Class InMemoryDatabaseConnection

java.lang.Object
org.dbunit.database.InMemoryDatabaseConnection

public final class InMemoryDatabaseConnection extends Object
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 Details

    • create

      public static IDatabaseConnection create() throws Exception
      Creates an IDatabaseConnection backed 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

      public static IDatabaseConnection create(String schema) throws Exception
      Creates an IDatabaseConnection backed 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