Reputation: 107
Could someone create a JUnit test in NetBeans for the code that I have pasted below? I'm not quite sure what to do once I've created the actual test.
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());
}
}
Upvotes: 1
Views: 3247
Reputation: 13388
There are numerous APIs that claim to automate this process. Perhaps one of them would be helpful for you:
Upvotes: 0
Reputation: 18939
I suggest using the "create JUnit test" button in the IDE. This will place the class in the right place for you. You can then copy'n'paste your code into that test. If that button is not visible on your toolbar, right-click on your toolbar and add that button from the customise menu. I also recommend adding the "test this class" button.
Upvotes: 0
Reputation: 80166
You have the class that you need to write JUnit tests for. Read this: Writing JUnit Tests in NetBeans IDE and Introduction to Unit Testing
Upvotes: 3