Open rbsrcy opened 8 years ago
Create a class CsvDataSetLoader
like this:
import com.github.springtestdbunit.dataset.AbstractDataSetLoader;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.csv.CsvURLDataSet;
import org.springframework.core.io.Resource;
public class CsvDataSetLoader extends AbstractDataSetLoader {
protected IDataSet createDataSet(Resource resource) throws Exception {
return new CsvURLDataSet(resource.getURL());
}
}
Put this code on test class:
@DbUnitConfiguration(dataSetLoader = CsvDataSetLoader.class)
@philwebb Hi:
When using custom Csvloader to load csv dataset ,the dbunit frame require to put a file named 'table-ordering.txt' in the same with csv directory.
How to asign csv and table name when @DatabaseSetup and @ExpectedDatabase asign to the same table.
//BaseTest.java @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/spring/spring*.xml") @TransactionConfiguration(defaultRollback = false,transactionManager="transactionManager") @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, TransactionDbUnitTestExecutionListener.class }) public class BaseTest {}
//CsvDatasetTest.java @Transactional @DbUnitConfiguration(dataSetLoader = CsvDataSetLoader.class) public class CsvDatasetTest extends BaseTest { @Autowired private PersonService personService;
}