有人能在NetBeans中为我粘贴在下面的代码创建一个JUnit测试吗?我不太确定创建实际测试后该怎么办。
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());
}
}
您拥有编写JUnit测试所需的类。阅读:在NetBeans IDE中编写JUnit测试和单元测试简介
我建议在IDE中使用"创建JUnit测试"按钮。这将把课堂安排在适合你的位置。然后,您可以将代码复制并粘贴到该测试中。如果该按钮在工具栏上不可见,请右键单击工具栏,然后从自定义菜单中添加该按钮。我还建议添加"测试这个类"按钮。
有许多API声称可以自动化这个过程。也许其中一个会对你有所帮助:
- http://sourceforge.net/projects/amaticjunittool/
- http://sourceforge.net/projects/junitgenerator/
- http://sourceforge.net/projects/junittestmaker/
- http://sourceforge.net/projects/spike-test-gen/