How to use DbUnit with TestNG

I need to integrate DbUnit with TestNG.

1) Is it possible to use DbUnit with TestNG since DbUnit is basically a JUnit extension.
2) If so, how?

+4
source share
3 answers

Finally, I learned how to use DbUnit with TestNG!

Using an instance of IDatabaseTester works,

but another job: Extend AbstractDatabaseTester and implement getConnection and override the necessary functions. But one important thing is to call onSetup () and onTeardown () before and after testing.

Hope this helps ...

+2
source

Not sure what you are trying to do for sure, but perhaps Unitils would be helpful. This is similar to the dbunit extension, but is not limited to this, and supports integration with TestNg (by extending the UnitilsTestNG class for your test test).

+1
source

Here is a simple class that performs the required function.

public class SampleDBUnitTest { IDatabaseTester databaseTester; IDataSet dataSet; @BeforeMethod public void setUp() throws Exception { // These could come as parematers from TestNG final String driverClass = "org.postgresql.Driver"; final String databaseUrl = "jdbc:postgresql://localhost:5432/database"; final String username = "username"; final String password = "password"; dataSet = new FlatXmlDataSet(Thread.currentThread().getContextClassLoader().getResourceAsStream("dataset.xml")); databaseTester = new JdbcDatabaseTester(driverClass, databaseUrl, username, password); databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT); databaseTester.setDataSet(dataSet); databaseTester.setTearDownOperation(DatabaseOperation.NONE); databaseTester.setDataSet(dataSet); databaseTester.onSetup(); } @AfterMethod public void tearDown() throws Exception { databaseTester.onTearDown(); } @Test public void t() throws Exception { // Testing, testing } } 
0
source

All Articles