Java JUnit Testing for Method
I am new at JUnit Testing and curious about how it works. Currently I am
trying to get an unit test to pass.
The test Method is
@Test
public void ensure_equals_method_is_properly_coded ()
{
assertTrue(employees.get(0).equals(employees.get(2)));
assertFalse(employees.get(0).equals(employees.get(1)));
assertFalse(employees.get(0).equals(employees.get(3)));
}
I have an ArrayList already populated with values in it. From what I
understand I am suppose to write a method called equals() to get this test
to pass for my task. My question is how will this method find the method
to test against. I have created an equals() method in a class called
Persons but I don't know if it's even being called when I run the test.
My second question is questioning the logic in my equal() method. So far I
have this.
public boolean equals() {
if (employees.get(0).equals(employees.get(2)))
return true;
return false;
}
This should return true because the first test item asserts that is true.
Is my logic correct on this?
No comments:
Post a Comment