Class DbUnitRunner

java.lang.Object
com.github.mjeanroy.dbunit.core.runner.DbUnitRunner

public class DbUnitRunner extends Object
Generic class to run DbUnit before/after test method invocation.
  • Constructor Details

    • DbUnitRunner

      public DbUnitRunner(Class<?> testClass, JdbcConnectionFactory factory)
      Create runner.
      DbUnit DataSet will be automatically detected:
      1. If method to launch contains DbUnitDataSet annotation, it is used.
      2. If DbUnitDataSet annotation is not found, a log is displayed, but runner will not failed.
      Parameters:
      testClass - Class to test.
      factory - Factory to get new SQL connection before and after test methods.
      Throws:
      DbUnitException - If dataSet parsing failed.
    • DbUnitRunner

      public DbUnitRunner(Class<?> testClass, DataSource dataSource)
      Create runner.
      Parameters:
      testClass - Class to test.
      dataSource - DataSource to get new SQL connection before and after test methods.
      Throws:
      DbUnitException - If dataSet parsing failed.
      See Also:
      • DbUnitRunner(Class, JdbcConnectionFactory, DbUnitClassContext)
    • DbUnitRunner

      public DbUnitRunner(Class<?> testClass)
      Create runner and extract the JDBC Connection factory from the testClass that should be annotated with DbUnitConnection.
      Parameters:
      testClass - The tested class.
  • Method Details

    • beforeTest

      public void beforeTest(Method testMethod)
      Load data set before test execution:
      1. Get new SQL connection.
      2. Load DataSet and execute setup operation.
      3. Close SQL connection.
      Parameters:
      testMethod - Method to execute.
    • afterTest

      public void afterTest(Method testMethod)
      Unload data set after test execution:
      1. Get new SQL connection.
      2. Remove DataSet and execute tear down operation.
      3. Close SQL connection.
      Parameters:
      testMethod - Executed method.
    • getFactory

      public JdbcConnectionFactory getFactory()
      Get factory
      Returns:
      factory
    • getConnection

      public Connection getConnection()
      Get JDBC Connection to the target database.
      Returns:
      SQL Connection.