有人可以在NetBeans中爲我粘貼的代碼創建一個JUnit測試嗎?我不確定在創建實際測試後該怎麼做。JUnit在Netbeans上測試一個類
package prog3;
import java.util.ArrayList; import java.util.Iterator;
public class MedicineClass
{
private String MedicineName;
private int MedicineRegNum;
private ArrayList RelatedMedicine;
public MedicineClass(String newMedicineName, int newMedicineRegNum)
{
newMedicineName = MedicineName;
newMedicineRegNum = MedicineRegNum;
RelatedMedicine = new ArrayList();
}
public void setMedicine(String newMedicineName)
{
newMedicineName = MedicineName;
}
public String getMedicineNameAndNum()
{
return "Medicine Registration Number: " + MedicineRegNum + "Medicine Name: " + MedicineName;
}
public void Medicine(Medicine Drug)
{
RelatedMedicine.add(Drug);
}
public void addMedicine(String newMedicineName, int newMedicineRegNum)
{
Medicine temp = new Medicine(newMedicineName, newMedicineRegNum);
RelatedMedicine.add(temp);
}
public void listAllMedicines()
{
StringBuilder sb = new StringBuilder();
Iterator lst = RelatedMedicine.iterator();
while (lst.hasNext())
{
Medicine temp = (Medicine)lst.next();
sb.append(temp.getNameandRegNum());
sb.append("\n");
}
System.out.println(sb.toString());
}
}
看起來像功課;)你想幹什麼你的單元測試斷言? –