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類通過從控制檯詢問詳細信息來創建員工對象,並創建包含所有員工對象的散列表。如何比較在Junit測試用例中其值爲類對象的兩個哈希映射?
你在你的Employee類中覆蓋了'equals'嗎? – assylias
什麼是「AllFunctions」? – Rainer
請提供[mcve]。 –