SQL dataset support for DbUnit and spring-test-dbunit extension for Spring test.
Are equivalents:
-
SQL dataset:
insert into profile (id, key) values ('1st', 'first'); insert into user (id, email, profile_id) values (1, 'first@domain.org', '1st');
-
XML dataset:
<dataset> <profile id="1st" key="first"> <user id="1" email="first@domain.org" profile_id="1st"> </dataset>
To use SQL support, add this dependency to your pom.xml
:
<dependency>
<groupId>fr.pinguet62</groupId>
<artifactId>dbunit-sql</artifactId>
<version>...</version>
</dependency>
It's necessary to add DbUnit and/or spring-test-dbunit dependencies, because this project use provided
scope.
From Getting Started:
// [...]
import fr.pinguet62.dbunit.sql.ext.SqlDataSet;
public class SqlTest extends DBTestCase {
// [...]
@Override
protected IDataSet getDataSet() throws Exception {
return new SqlDataSet(getClass().getResourceAsStream("/dataset.sql"));
// return new SqlDataSet(getClass().getResourceAsStream("insert into profile (id, key) values ('1st', 'first');"));
}
}
// [...]
import fr.pinguet62.dbunit.sql.springtest.SqlDataSetLoader;
// [...]
@TestExecutionListeners({ /*...,*/ TransactionDbUnitTestExecutionListener.class })
@DbUnitConfiguration(dataSetLoader = SqlDataSetLoader.class)
@DatabaseSetup("/dataset.sql")
public class SqlTest {
// [...]
}