我有方法:
public void addDepartment(String[] list, Department department) {
if(list[0]!=null && list[0]!=""){
department.setDepName(list[0]);
this.departmentDao.addOrEditDepartment(department);
}
}
我为它做了一个测试用例..
public void testAddDepartment(){
Department department = new Department();
String[] list = new String[1];
list[0] = "mmm";
department.setDepId(120);
department.setDepName(list[0]);
service.addDepartment(list, department);
assertEquals("mmm",service.getDepartment(120).getDepName());
//assertNotNull(service.getDepartment(112).getDepName());
}
但是出现了assertequals中的错误,其中assertequal不是函数(string,void)..但我不知道如何测试它...任何帮助plzz?
答案 0 :(得分:2)
方法assertEquals
检查两个对象的身份。
在这里检查:
department
service.addDepartment(list, department)
但方法addDepartment
返回void
,因此无法在此方法中使用。
您可能希望执行以下操作:
@Test
public void testAddDepartment(){
Department department = new Department();
String[] list = new String[1];
list[0] = "mmm";
department.setDepId(120);
department.setDepName(list[0]);
service.addDepartment(list, department);
// Probably you need to change this to what you like to test
assertArrayEquals(list, service.getListNotShownHere());
}