Forum Stats

  • 3,874,309 Users
  • 2,266,718 Discussions
  • 7,911,811 Comments

Discussions

Noob question in JUnit.

843810
843810 Member Posts: 46,938
Hello all.
Starts to use JUnit in NetBeans 5.5. But can`t understand how it works.
Have such simple code:
/**
     * Test of isCloseTime method, of class stInterface.TestSettings.
     */
    public void testIsCloseTime() {
        System.out.println("isCloseTime");
        
        boolean expResult = true;
        boolean result = true;
        assertEquals(expResult, result);
        
        // TODO review the generated test code and remove the default call to fail.
        fail(expResult + " is not equal " + result);
    }
The push Alt+F6 for test starting and get:
true is not equal true
junit.framework.assertionFailedError

Please, expalain me, what I have done wrong?

Comments

  • 800387
    800387 Member Posts: 5,078
    The assertEquals passes (since true is equal to true). However, you have a line invoking fail right below. This will throw an AssertionError indicating the test has failed. Remove or comment out the line containing the fail invocation (as the auto-generated comments clue you to do).

    - Saish
This discussion has been closed.