An example is worth an explanation I believe:
Here's my persistence level test super class:
@TransactionConfiguration(defaultRollback = true)
@TestExecutionListeners({ DataSetTestExecutionListener.class })
@ContextConfiguration(locations =
{"file:src/main/webapp/WEB-INF/hibernateContext.xml",
"file:src/main/webapp/WEB-INF/daoContext.xml"})
public class BaseDaoHibernateTest extends
AbstractTransactionalTestNGSpringContextTests {
/**
* Empty method that is called before the group of test
* it triggers the insertion of the DBUnit base data script
*/
@DataSet(value = "classpath:basedata.xml")
@BeforeClass(groups = "dao")
public void setData() {
logger.warn("Base data are being injected by DBUnit");
}
}
If I run a test extending this base class, the DBunit data injection won't
be triggered.
public final class CommonDaoHibernateTest extends BaseDaoHibernateTest {
@Autowired
private CommonDAOHibernate commonDAOHibernate;
/**
* check if the most basic query works out. Verify the Hibernate setup
*/
@Test(groups = "common")
public void queryTest() {
String queryStr = "id = 'admin'";
List result = commonDAOHibernate.findObject(User.class, queryStr);
assertNotNull(result);
}
If I add the @DataSet annotation to the test method, then it works.
My idea is to get a basic set of table populated for the whole suite, then
inject specific Spring Bean based data for each test.
Am I missing something? Or is it because the setData() method in
BaseDaohibernateTest is not a proper test itself?
Original issue reported on code.google.com by nodje...@gmail.com on 23 Apr 2009 at 8:51
Original issue reported on code.google.com by
nodje...@gmail.com
on 23 Apr 2009 at 8:51