Hi i need help implementing the proper code for a JUnit test within my code for
ID: 3905104 • Letter: H
Question
Hi i need help implementing the proper code for a JUnit test within my code for eclipse oxygen:
package medical.com.medicalApplication.model;
import static org.junit.Assert.*;
import org.junit.Test;
public class Doctor {
private String name;
private String id;
public Doctor(String name, String id) {
super();
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return "Doctor Name:"+ name + " ID: "+id;
}
}
Explanation / Answer
//Doctor.java public class Doctor { private String name; private String id; public Doctor(String name, String id) { super(); this.name = name; this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } @Override public String toString() { return "Doctor Name:"+ name + " ID: "+id; } } ====================================== //DoctorTest.java import static org.junit.Assert.*; import org.junit.Test; public class DoctorTest { Doctor doctor = new Doctor("Doctor name", "Doctor Id"); @Test public void TestGetName(){ assertEquals(doctor.getName(),"Doctor name"); } @Test public void TestGetID(){ assertEquals(doctor.getId(),"Doctor Id"); } @Test public void TestToString(){ assertEquals(doctor.toString(),"Doctor Name:Doctor name ID: Doctor Id"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.