-1

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

1 回答 1

0

testFindEmployeeByID()-method中的这部分看起来是错误的:

testFindEmployeeByID abc = new testFindByEmployeeID();

testFindEmployeeByID测试类名称也是?您可能打算实例化包含实际方法的类findEmployeeByID

于 2012-10-07T10:12:47.783 回答