Pattern selector

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

  1. Assert.fail() has thrown an AssertionError
    JUnit
    4
    24
    3
  2. JUnit test assertion failed
    JUnit
    178
    2918
    155

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.AssertionError
    at org.junit.Assert.fail(Assert.java:92)
    at org.junit.Assert.fail(Assert.java:100)
    at org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.testFailureWithoutExplicitDeclarePrecedence(AbstractAspectJAdvisorFactoryTests.java:579)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
22 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. mbrukmanvia GitHub3 days ago
    expected:<2> but was:<4>
    Show stack trace
  2. yanokwavia GitHub3 days ago
    expected:<5> but was:<0>
    Show stack trace
  3. wildfly-civia GitHub4 days ago
    expected:<11> but was:<19>
    Show stack trace
  4. wildfly-civia GitHub4 days ago
    expected:<11> but was:<19>
    Show stack trace
  5. wildfly-civia GitHub4 days ago
    expected:<11> but was:<19>
    Show stack trace
  6. wildfly-civia GitHub4 days ago
    block not present after 5000 ms
    Show stack trace
  7. wildfly-civia GitHub4 days ago
    expected:<12> but was:<20>
    Show stack trace
  8. cdjacksonvia GitHub5 days ago
    198.75
    Show stack trace
  9. jenstroegervia GitHub5 days 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
  10. BO41via GitHub5 days ago
    expected:<0> but was:<2>
    Show stack trace