Package org.dbunit

Class DatabaseTestCase

java.lang.Object
org.dbunit.DatabaseTestCase
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.TestInstantiationAwareExtension
Direct Known Subclasses:
DBTestCase

public abstract class DatabaseTestCase extends Object implements org.junit.jupiter.api.extension.InvocationInterceptor
Convenience class for writing JUnit tests with dbunit easily.
Note that there are some even more convenient classes available such as DBTestCase.
Since:
1.0 (Feb 17, 2002)
Version:
$Revision$
Author:
Manuel Laflamme
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default constructor.
    protected
    Constructs a test case with the given name.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Deprecated.
    since 2.4.4 define a user defined getOperationListener() in advance
    protected abstract IDatabaseConnection
    Returns the test database connection.
    protected IDatabaseTester
    Gets the IDatabaseTester for this testCase.
    If the IDatabaseTester is not set yet, this method calls newDatabaseTester() to obtain a new instance.
    protected abstract IDataSet
    Returns the test dataset.
    Returns this test case's name.
    Returns the operation listener used by the database tester, creating a default one on first access.
    Returns the database operation executed in test setup.
    Returns the database operation executed in test cleanup.
    protected IDatabaseTester
    Creates a IDatabaseTester for this testCase.
    A DefaultDatabaseTester is used by default.
    protected void
    Prepares the database, using the database tester, connection, and dataset from getDatabaseTester(), getConnection(), and getDataSet().
    protected void
    Designed to be overridden by subclasses in order to set additional configuration parameters for the IDatabaseConnection.
    protected void
    Runs the tear-down operation and releases the database tester.
    protected void
    tearDown(Throwable testFailure)
    Runs tear down the same as tearDown(), for use when a test failure is already in flight (e.g. calling this from a catch/finally around the test body).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod, interceptTestTemplateMethod

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • DatabaseTestCase

      protected DatabaseTestCase()
      Default constructor.
    • DatabaseTestCase

      protected DatabaseTestCase(String name)
      Constructs a test case with the given name.
      Parameters:
      name - the test case name.
  • Method Details

    • getName

      public String getName()
      Returns this test case's name.
      Returns:
      this test case's name.
    • getConnection

      protected abstract IDatabaseConnection getConnection() throws Exception
      Returns the test database connection.
      Returns:
      the test database connection.
      Throws:
      Exception - if the connection cannot be retrieved or created.
    • getDataSet

      protected abstract IDataSet getDataSet() throws Exception
      Returns the test dataset.
      Returns:
      the test dataset.
      Throws:
      Exception - if the dataset cannot be retrieved or created.
    • newDatabaseTester

      protected IDatabaseTester newDatabaseTester() throws Exception
      Creates a IDatabaseTester for this testCase.
      A DefaultDatabaseTester is used by default.
      Returns:
      the newly created database tester.
      Throws:
      Exception - if the database tester cannot be created.
    • setUpDatabaseConfig

      protected void setUpDatabaseConfig(DatabaseConfig config)
      Designed to be overridden by subclasses in order to set additional configuration parameters for the IDatabaseConnection.
      Parameters:
      config - The settings of the current IDatabaseConnection to be configured
    • getDatabaseTester

      protected IDatabaseTester getDatabaseTester() throws Exception
      Gets the IDatabaseTester for this testCase.
      If the IDatabaseTester is not set yet, this method calls newDatabaseTester() to obtain a new instance.
      Returns:
      the IDatabaseTester for this testCase.
      Throws:
      Exception - if a new database tester cannot be created.
    • closeConnection

      @Deprecated protected void closeConnection(IDatabaseConnection connection) throws Exception
      Deprecated.
      since 2.4.4 define a user defined getOperationListener() in advance
      Close the specified connection. Override this method of you want to keep your connection alive between tests.
      Parameters:
      connection - the connection to close.
      Throws:
      Exception - if the connection cannot be closed.
    • getSetUpOperation

      protected DatabaseOperation getSetUpOperation() throws Exception
      Returns the database operation executed in test setup.
      Returns:
      the database operation executed in test setup.
      Throws:
      Exception - if the operation cannot be determined.
    • getTearDownOperation

      protected DatabaseOperation getTearDownOperation() throws Exception
      Returns the database operation executed in test cleanup.
      Returns:
      the database operation executed in test cleanup.
      Throws:
      Exception - if the operation cannot be determined.
    • setUp

      protected void setUp() throws Exception
      Prepares the database, using the database tester, connection, and dataset from getDatabaseTester(), getConnection(), and getDataSet().
      Throws:
      Exception - if the setup operation fails.
    • tearDown

      protected void tearDown() throws Exception
      Runs the tear-down operation and releases the database tester.
      Throws:
      Exception - if the tear-down operation fails.
    • tearDown

      protected void tearDown(Throwable testFailure) throws Throwable
      Runs tear down the same as tearDown(), for use when a test failure is already in flight (e.g. calling this from a catch/finally around the test body). A tear-down failure never replaces the given testFailure; it is instead attached via Throwable.addSuppressed(java.lang.Throwable) so the original failure remains the one reported, with the tear-down failure still visible alongside it.
      Parameters:
      testFailure - The throwable already in flight from the test body, or null if there is none, in which case this behaves the same as tearDown().
      Throws:
      Throwable - testFailure, if not null; otherwise a tear-down failure, if one occurred.
      Since:
      3.4.0
    • getOperationListener

      protected IOperationListener getOperationListener()
      Returns the operation listener used by the database tester, creating a default one on first access.
      Returns:
      The IOperationListener to be used by the IDatabaseTester.
      Since:
      2.4.4