dbunitunit
is a small project that provides JUnit utilities
that make it easy to use DbUnit in your unit tests. This project
is best used with the h2unit
project as well.
public class TestCaseDbUnitRule {
public final DbUnitRule dbUnitRule = new DbUnitRule(this);
@Rule
public final TestRule chain = RuleChain.outerRule(new H2Rule(this)).around(this.dbUnitRule);
@DbUnitTester(connectionUrl = "jdbc:h2:mem:test")
private Connection c;
@DbUnitTester
@H2Connection(url = "jdbc:h2:mem:test", user = "SA", password = "", threadSafe = true)
private Connection h2;
public TestCaseDbUnitRule() {
super();
}
@Test
public void testInjection() {
assertNotNull(h2);
assertNotNull(c);
final IDatabaseTester tester = this.dbUnitRule.getIDatabaseTester(this.h2);
assertNotNull(tester);
}
}