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
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
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedDatabaseTestCase(String name) Constructs a test case with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcloseConnection(IDatabaseConnection connection) Deprecated.protected abstract IDatabaseConnectionReturns the test database connection.protected IDatabaseTesterGets the IDatabaseTester for this testCase.
If the IDatabaseTester is not set yet, this method calls newDatabaseTester() to obtain a new instance.protected abstract IDataSetReturns the test dataset.getName()Returns this test case's name.protected IOperationListenerReturns the operation listener used by the database tester, creating a default one on first access.protected DatabaseOperationReturns the database operation executed in test setup.protected DatabaseOperationReturns the database operation executed in test cleanup.protected IDatabaseTesterCreates a IDatabaseTester for this testCase.
ADefaultDatabaseTesteris used by default.protected voidsetUp()Prepares the database, using the database tester, connection, and dataset fromgetDatabaseTester(),getConnection(), andgetDataSet().protected voidsetUpDatabaseConfig(DatabaseConfig config) Designed to be overridden by subclasses in order to set additional configuration parameters for theIDatabaseConnection.protected voidtearDown()Runs the tear-down operation and releases the database tester.protected voidRuns tear down the same astearDown(), 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, waitMethods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod, interceptTestTemplateMethodMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
DatabaseTestCase
protected DatabaseTestCase()Default constructor. -
DatabaseTestCase
Constructs a test case with the given name.- Parameters:
name- the test case name.
-
-
Method Details
-
getName
Returns this test case's name.- Returns:
- this test case's name.
-
getConnection
Returns the test database connection.- Returns:
- the test database connection.
- Throws:
Exception- if the connection cannot be retrieved or created.
-
getDataSet
Returns the test dataset.- Returns:
- the test dataset.
- Throws:
Exception- if the dataset cannot be retrieved or created.
-
newDatabaseTester
Creates a IDatabaseTester for this testCase.
ADefaultDatabaseTesteris used by default.- Returns:
- the newly created database tester.
- Throws:
Exception- if the database tester cannot be created.
-
setUpDatabaseConfig
Designed to be overridden by subclasses in order to set additional configuration parameters for theIDatabaseConnection.- Parameters:
config- The settings of the currentIDatabaseConnectionto be configured
-
getDatabaseTester
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.since 2.4.4 define a user definedgetOperationListener()in advanceClose 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
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
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
Prepares the database, using the database tester, connection, and dataset fromgetDatabaseTester(),getConnection(), andgetDataSet().- Throws:
Exception- if the setup operation fails.
-
tearDown
Runs the tear-down operation and releases the database tester.- Throws:
Exception- if the tear-down operation fails.
-
tearDown
Runs tear down the same astearDown(), 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 viaThrowable.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, ornullif there is none, in which case this behaves the same astearDown().- Throws:
Throwable- testFailure, if notnull; otherwise a tear-down failure, if one occurred.- Since:
- 3.4.0
-
getOperationListener
Returns the operation listener used by the database tester, creating a default one on first access.- Returns:
- The
IOperationListenerto be used by theIDatabaseTester. - Since:
- 2.4.4
-
getOperationListener()in advance