org.unitils.dbunit.annotation
Annotation Type DataSet


@Target(value={TYPE,METHOD})
@Retention(value=RUNTIME)
@Inherited
public @interface DataSet

Annotation indicating that a data set should be loaded before the test run.

If a class is annotated, a test data set will be loaded before the execution of each of the test methods in the class. A data set file name can explicitly be specified. If no such file name is specified, first a data set named 'classname'.'testmethod'.xml will be tried, if no such file exists, 'classname'.xml will be tried. If that file also doesn't exist, an exception will be thrown. Filenames that start with '/' are treated absolute. Filenames that do not start with '/', are relative to the current class.

A test method can also be annotated with DataSet in which case you specify the dataset that needs to be loaded before this test method is run. Again, a file name can explicitly be specified or if not specified, the default will be used: first 'classname'.'methodname'.xml and if that file does not exist 'classname'.xml.

Examples:


 '    @DataSet
      public class MyTestClass extends UnitilsJUnit3 {
 '
          public void testMethod1(){
          }
 '
 '        @DataSet("aCustomFileName.xml")
          public void testMethod2(){
          }
      }
 
Will load a data set file named MyTestClass.xml or MyTestClass-testMethod1.xml for testMethod1 in the same directory as the class. And for testMethod2 a data set file named aCustomFileName.xml in the same directory as the class is loaded.


      public class MyTestClass extends UnitilsJUnit3 {
 '
          public void testMethod1(){
          }
 '
 '        @DataSet
          public void testMethod2(){
          }
      }
 
Will not load any dataset for testMethod1 (there is no class level data set). Will load a data set file named MyTestClass.xml or MyTestClass.testMethod2.xml for testMethod2.

Author:
Filip Neven, Tim Ducheyne

Optional Element Summary
 Class<? extends DataSetFactory> factory
          The factory that needs to be used to read the dataset file and create a MultiSchemaDataSet object
 Class<? extends DataSetLoadStrategy> loadStrategy
          The strategy that needs to be used to get the dbunit dataset into the database
 String[] value
          The file name of the data set.
 

value

public abstract String[] value
The file name of the data set. If left empty, the default filename will be used: first 'classname'.'testMethodname'.xml will be tried, if that file does not exist, 'classname'.xml is tried. If that file also does not exist, an exception is thrown.

Returns:
the fileName, empty for default
Default:
{}

loadStrategy

public abstract Class<? extends DataSetLoadStrategy> loadStrategy
The strategy that needs to be used to get the dbunit dataset into the database

Returns:
An implementation class of DataSetLoadStrategy. Use the default value DataSetLoadStrategy to make use of the default loadStragegy configured in the unitils configuration.
Default:
org.unitils.dbunit.datasetloadstrategy.DataSetLoadStrategy.class

factory

public abstract Class<? extends DataSetFactory> factory
The factory that needs to be used to read the dataset file and create a MultiSchemaDataSet object

Returns:
An implementation class of DataSetFactory. Use the default value DataSetFactory to make use of the default DataSetLoadStrategy configured in the unitils configuration.
Default:
org.unitils.dbunit.datasetfactory.DataSetFactory.class


Copyright © 2011. All Rights Reserved.