我有我的Student
類的克隆方法,我想測試它是否工作正常(DOB和地址和深克隆,當然是淺克隆)如何JUnit測試我的克隆方法?
我需要的代碼的第二塊幫助,我不知道如何正確地測試,如果地址和出生日期被深克隆,當然是淺克隆
...
public Student clone() {
Student clone = new Student();
clone.dob = (Date) this.dob.clone();
clone.address = this.address.clone();
clone.course = this.course;
return clone;
}
...
public void testCloning() {
Student test = clone?
assertEquals(Student, Student.clone())
}
請好好解釋一下你的問題。 – Jayesh
寫一個equals()方法怎麼樣(當然只有當它們也應該被視爲相等時) – kism3t
Address和dob數組或其他對象?如果沒有,我不確定我是否理解爲什麼您認爲深層副本適用於他們 –