Often I find that I create the same unit test methods for the getters \ seters, c'tors and Object methods (hashCode, equals and toString). What I'm trying to achieve with the Eclipse IDE is the automation of this procedure. consider this example:
public Class Person {
private String id;
private String name;
public Person(String id, String name){
this.id = id;
this.name = name;
}
public String getId() { return id; }
public void setId(String id) {
this.id = id;
}
public String getName() { return name; }
public void setName(String name) {
this.name = name;
}
@override
public int hashCode(){ ... }
public boolean equals(Person other){ ... }
public String toString(){ ... }
}
The unit test class will look something like this:
public class PersonTest extends TestCase
{
@override
public void setup() {
Person p1 = new Person("1","Dave");
Person p2 = new Person("2","David");
}
@override
public void tearDown() {
Person p1 = null;
Person p2 = null;
}
public void testGetId() {
p1.setId("11");
assertEquals("Incorrect ID: ", "11", p1.getId());
}
public void testGetName() { }
public void testEquals_NotEquals() { }
public void testEquals_Equals() { }
public void testHashCode_Valid() { }
public void testHashCode_NotValid() { }
public void testToString() { }
}
This skeleton is similar to the vast majority of classes created. can it be automated using eclipse?
source
share