gudii9
asked on
how to test mutators, constructors, comparable, toString, Exceptions using junit in java
Hi,
how to test mutators, constructors, comparable interface(say i have Employee objects with FirstName, LastName, Age etc to compareTo()), toString, Exceptions, equals()(how assertTrue different from assertEquals()), objects in equality using junit in java. Why junit onwards methods do not need to prefix with testXyz() like that. Please advise
how to test mutators, constructors, comparable interface(say i have Employee objects with FirstName, LastName, Age etc to compareTo()), toString, Exceptions, equals()(how assertTrue different from assertEquals()), objects in equality using junit in java. Why junit onwards methods do not need to prefix with testXyz() like that. Please advise
ASKER
//The Employee class must have a method named equals which takes an Employee object as a parameter
//and compares the member variables for equality.
Employee first = new Employee("John", "Doe", 43);
Employee second = new Employee("John", "Doe", 43);
assertTrue(first.equals(second));
//The Employee class must have a method named toString which creates a string from the member variables
assertEquals("John Doe, age 43", first.toString();
i wonder what assertTrue(first.equals(se
and
assertEquals("John Doe, age 43", first.toString();
prints in this case. please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
assertEquals compares the parameters for equality
Here are some tests for an Employee object.
Open in new window
Use the @Test annotation before each test method. It doesn't matter what the method is named.
Open in new window