it's my first time using JUNIT and I literally cannot get it to work.
I've got a person class, in which has firstName and lastName, and a test class in which I need to test the methods. Everytime I attempt to test one though, if i've wrote a test for the particular method, it fails.
Here is my code.
Person Class
public class Person {
private String firstName;
private String lastName;
public Person (String a, String b) {
firstName = a;
lastName = b;
}
public String getfirstName() {
return firstName;
}
public void setfirstName(String firstName) {
this.firstName = firstName;
}
public String getlastName() {
return lastName;
}
public void setlastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return firstName + " " + lastName;
}
}
Person Test class
public class PersonTest {
Person p1;
public PersonTest() {
Person p1 = new Person ("Thomas", "Brown");
}
@Before
public void setUp() {}
@After
public void tearDown() {}
@Test
public void testGetfirstName() {
assertEquals("Thomas", p1.getfirstName());
}
@Test
public void testSetfirstName() {}
@Test
public void testGetlastName() {
assertEquals("Brown", p1.getlastName());
}
@Test
public void testSetlastName() {}
@Test
public void testToString() {
assertEquals("Thomas Brown", p1.toString());
}
}
Could anyone point me in the right direction?
Person p1...to your@Beforemethod.