Magazine
 
DbTesting with DbUnit

"login";
private FlatXmlDataSet loadedDataSet;
// Provide a connection to the database
protected IDatabaseConnection
getConnection() throws Exception{
Class.forName
("com.mysql.jdbc.Driver");
Connection jdbcConnection =
DriverManager.getConnection
("jdbc:mysql:/
/localhost:3306/
hrapptest", "root", "root");
return new
DatabaseConnection(jdbcConnection);
}
// Load the data which will be
inserted for the test
protected IDataSet getDataSet()
throwsException{
loadedDataSet = new

 

FlatXmlDataSet(this.getClass().
getClassLoader().
getResourceAsStream("input.xml"));
return loadedDataSet;
}
// Check that the data has been loaded.
public void testCheckLoginDataLoaded()
throws Exception{
assertNotNull(loadedDataSet);
int rowCount =
loadedDataSet.getTable
(TABLE_LOGIN).
getRowCount();
assertEquals(2, rowCount);
}
}

Running Test :

Now, in Eclipse, go to Run->Run
As and click "JUnit Test" to run tests.
If testing is successful then a green strip appears at the left of the eclipse window. If any of the test fails then it turns into a red strip indicating failure of any test.



Sept 2007 | Java Jazz Up | 43
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   Download PDF