如何为此代码构建测试用例?我的testFindEmployeeByID出了什么问题?

时间:2012-10-07 08:42:44

标签: java testing junit

如何为此代码构建测试用例?请检查底部的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);
}

1 个答案:

答案 0 :(得分:0)

testFindEmployeeByID() - 方法中的这一部分看起来不对:

testFindEmployeeByID abc = new testFindByEmployeeID();

testFindEmployeeByID是否也是测试类名?您可能想要实例化包含实际findEmployeeByID - 方法的类。