Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. Assert.assertEquals() has thrown an AssertionError
    JUnit
    12
    368
    32
  2. JUnit test assertion failed
    JUnit
    178
    2916
    155

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.AssertionError: expected:<0> but was:<1>
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:743)
    at org.junit.Assert.assertEquals(Assert.java:118)
    at org.junit.Assert.assertEquals(Assert.java:555)
6 frames hidden

Solution

chinthana10 months ago

AssertionError is thrown when using JUnit's internal assertions methods compare two different values and those are not equal. Also, the developer can invoke the method when the test logic fails.

The simplest code to reproduce the error is the following:

import static org.junit.Assert.fail;

public class FailTest { 

   @Test 
   public void shouldAssertFail() { 
      ...
      if( ... ) {
         fail("Any message");
      }
   } 
}

Mind the static import. The fail is part of the JUnit API.

Your best course of action is to use the debugger to see why the test is failing and what is the condition that is not being met.

External results for this pattern (10)

  1. wildfly-civia GitHub1 day ago
    expected:<11> but was:<19>
    Show stack trace
  2. wildfly-civia GitHub1 day ago
    expected:<11> but was:<19>
    Show stack trace
  3. wildfly-civia GitHub1 day ago
    expected:<11> but was:<19>
    Show stack trace
  4. wildfly-civia GitHub1 day ago
    block not present after 5000 ms
    Show stack trace
  5. wildfly-civia GitHub1 day ago
    expected:<12> but was:<20>
    Show stack trace
  6. cdjacksonvia GitHub1 day ago
    198.75
    Show stack trace
  7. jenstroegervia GitHub1 day ago
    The warning results do not match expected:<[MessageId.PKG_012, MessageId.OPF_061, MessageId.OPF_003, MessageId.PKG_012]> but was:<[MessageId.OPF_003, MessageId.PKG_012, MessageId.OPF_061, MessageId.PKG_012]>
    Show stack trace
  8. BO41via GitHub2 days ago
    expected:<0> but was:<2>
    Show stack trace
  9. hhh0505via GitHub2 days ago
    expected:<Sun Jan 01 05:00:00 EST 2017> but was:<Sun Jan 01 10:00:00 EST 2017>
    Show stack trace
  10. ejona86via GitHub2 days ago