Hi Jeff
Below is part of one of my test classes:
import za.co.q3.prophecy_PM.dao.*;
import java.sql.*;
import ......
public class testAuditDAO {
//Class for getting connection
private SysConnection dbconn;
private Connection conn;
private ResultSet resultSet;
private SysUtil sysUtil = new SysUtil();
private PreparedStatement preparedStatement;
private int actualAuditId = sysUtil.getGuid();
private int expectedAuditId = 0;
public static junit.framework.Test suite() {
//allow this test to be run with the old test runners
return new JUnit4TestAdapter(testAuditDAO.class);
}
@Before public void runBeforeEachTest() throws
SQLException{
//Executes before each test
conn = dbconn.getConn();
//Make sure the connection is not null
assertNotNull(conn);
}
@After public void runAfterEachTest() throws SQLException{
//Executes after each test
dbconn.freeConnection(conn);
conn = null;
//make sure connection is closed
assertNull(conn);
}
/*
*Test Adding of Records
*/
@Test public void AddRecord() throws SQLException{
try{
preparedStatement =
conn.prepareStatement(dbconn.getSqlProperty("AuditDAO.addData"));
//set parameters
preparedStatement.setString(1,
String.valueOf(actualAuditId));
preparedStatement.executeUpdate();
}
catch (Exception e){
fail("Error when adding record: " + e.getMessage());
}
finally {
preparedStatement.close();
}
}
@Test public void GetAddedRecord() throws SQLException{
try{
preparedStatement = conn.prepareStatement("Select * from
Audit where AuditId = " + actualAuditId);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
//populate expected variables with values retrieved from
DB
expectedAuditId =
Integer.parseInt(resultSet.getString("auditId"));
}
else{
//No relevant record in the DB
fail("GetAddedRecord - No records where
returned from
the database.");
}
resultSet.close();
}
catch(Exception e){
fail("GetAddedRecord - Error when retrieving record: " +
e.getMessage());
}
finally{
preparedStatement.close();
}
//Do comparison between actual and expected record
DoAddCompare();
}
private void DoAddCompare(){
try{
assertEquals("The Audit_Id is not correct.",
expectedAuditId, actualAuditId);
}
catch(Exception e){
fail("Can't compare AuditId: " + e.getClass() + " - " +
e.getMessage());
}
}
}
And this is the suite that I am trying to create. It is
complaining because my class (testAuditDAO) does not extend
TestCase:
import junit.framework.Test;
import junit.framework.TestSuite;
import za.co.q3.prophecy_PM.junit.dao.*;
public class TestDAOSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
// Add all DAO test classes
suite.addTestSuite(testAuditDAO.class);
return suite;
}
// Runs the test suite using the textual runner.
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
___________________________________________________________________
For super low premiums, click here http://www.webmail.co.za/dd.pwm
http://www.webmail.co.za the South African FREE email service
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---