如何为这段代码构建一个测试用例?请检查底部的我的 TestCase 示例。我的 testFindEmployeeByID 有什么问题?
public Employee findEmployeeByID(int employeeID) throws HRSSystemException{
Employee result = null;
try {
PreparedStatement pStmt = conn
.prepareStatement("select * from Employee where ID = ?");
pStmt.setInt(1, employeeID);
ResultSet rs = pStmt.executeQuery();
if (rs.next()) {
result = new EmployeeImpl(rs.getInt("ID"),
rs.getString("FIRSTNAME"),
rs.getString("LASTNAME"),
rs.getInt("LEVEL"));
}
rs.close();
pStmt.close();
} catch (SQLException e) {
throw new HRSSystemException(HRSSystemException.ERROR_FIND_EMPLOYEE_ID,
e);
}
return result;
}
测试用例:
public void testFindEmployeeByID(){
testFindEmployeeByID abc = new testFindByEmployeeID();
Employee e = abc.findEmployeeByID(employeeID);
assertEquals(1,e.getID);
}