【发布时间】:2016-11-14 17:04:56
【问题描述】:
public class TestFailure {
@Test
public void testSwitch() throws CustomException {
Employee emp = new Employee(123, "John", "1234567890", "CEO", 0);
Map<Integer,Employee> exhmp = new HashMap<Integer, Employee>();
AllFunctions f = new AllFunctions();
exhmp.put(123, emp);
Map<Integer, Employee> htest= f.AddEmployee();
assertTrue(exhmp.equals(htest));
}
}
即使来自控制台的输入与员工对象中提供的相同,测试用例也会以测试失败的形式出现。但是,如果将员工类的不同属性单独与 htest 进行比较,则测试返回 true。 Allfunctions 类基本上通过从控制台询问详细信息来形成一个员工对象,并创建包含所有员工对象的 hashmap。
【问题讨论】:
-
您是否在 Employee 类中覆盖了
equals? -
什么是“AllFunctions”?