Answer 5: Assertion Messages
import junit.framework.TestCase;
import org.apache.commons.lang.math.*;
public class FractionTest extends TestCase {
private Fraction half;
private Fraction fourth;
protected void setUp() {
half = Fraction.getFraction(2, 4);
fourth = Fraction.getFraction(1, 4);
}
public void testAddition() {
Fraction actual = half.add(fourth);
Fraction expected = Fraction.getFraction(3, 4);
assertEquals("Could not add 1/2 to 1/4", expected, actual);
}
public void testSubtraction() {
Fraction actual = half.subtract(fourth);
Fraction expected = fourth;
assertEquals("Could not subtract 1/4 from 1/2",expected, actual);
}
public void testAddNumberToItself() {
Fraction actual = half.add(half);
Fraction expected = Fraction.ONE;
assertEquals("Could not add 1/2 to itself using same object",
expected, actual);
}
}