A few quick notes about using JUnit in the Eclipse IDE

Photo by Jongsun Lee on Unsplash
Detail of “page 2” of the Eclipse New Java Project wizard.
Detail of “page 2” of the Eclipse New Java Project wizard.
Detail of “page 2” of the Eclipse New Java Project wizard.
Detail of “page 2” of the Eclipse New Java Project wizard, with the new source folder icon highlighted.
Detail of “page 2” of the Eclipse New Java Project wizard, with the new source folder icon highlighted.
Detail of “page 2” of the Eclipse New Java Project wizard, with the new source folder icon highlighted.
    @Test
void testToString() {
System.out.println("toString");
int numer = RANDOM.nextInt(128) + 1;
int denom = numer * (RANDOM.nextInt(128) + 1) + 1;
Fraction fraction = new Fraction(numer, denom);
String expected = numer + "/" + denom;
String actual = fraction.toString().replace(" ", "");
assertEquals(expected, actual);
}
Detail of JUnit test results in Eclipse.
Detail of JUnit test results in Eclipse.
Detail of JUnit test results in Eclipse. The one test fails.
Detail of JUnit test results in Eclipse. The one test passes.
Detail of JUnit test results in Eclipse. The one test passes.
Detail of JUnit test results in Eclipse. The one test passes.
    // STUB TO FAIL THE FIRST TEST
public double numericApproximation() {
return -1.0;
}
    @Test
void testNumericApproximationPiApprox() {
Fraction piApprox = new Fraction(355, 113);
double expected = 3.1415929203539825;
double actual = piApprox.numericApproximation();
assertEquals(expected, actual, 0.00000001);
}
Example failure trace in Eclipse.
Example failure trace in Eclipse.
Example failure trace in Eclipse.
Result Comparison box in Eclipse.
Result Comparison box in Eclipse.
Result Comparison box in Eclipse.

is a composer and photographer from Detroit, Michigan. He has been working on a Java program to display certain mathematical diagrams.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store