necrofish666
necrofish666

Reputation: 75

JUnit assertEquals failure

I have the following test method which keeps failing:

/**
 * Test of averageResult method, of class MonthlyPayroll.
 */
public void testAverageResult() {
    System.out.println("averageResult");
    double[] MonthlySales = {4, 5, 6, 7, 8, 9};
    int howMany = 6;
    double expResult = 6.5;
    double epsilon = 1;
    double result = MonthlyPayroll.averageResult(MonthlySales, howMany);
    assertEquals(expResult, result, epsilon);
    // TODO review the generated test code and remove the default call to fail.
    fail("The test case is a prototype.");
}

The method works fine, when I debug the test, result and expResult are equal, but I get the following failure message:

compile-test-single:
Testsuite: pkgbmc.MonthlyPayrollTest
averageResult
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.109 sec

------------- Standard Output ---------------
averageResult
------------- ---------------- ---------------
Testcase: testAverageResult(pkgbmc.MonthlyPayrollTest): FAILED
The test case is a prototype.
junit.framework.AssertionFailedError: The test case is a prototype.
at pkgbmc.MonthlyPayrollTest.testAverageResult(MonthlyPayrollTest.java:61)

Anyone any idea why this is happening and how to fix it?

Upvotes: 1

Views: 1768

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81862

The call to fail

fail("The test case is a prototype.");

makes the test fail.

Note that in any IDE I know of you could have (double)clicked on the line

at pkgbmc.MonthlyPayrollTest.testAverageResult(MonthlyPayrollTest.java:61)

to get you exactly to the problematic line, which is NOT your assertEquals

Upvotes: 10

Related Questions