1. Explore
  2. »
  3. JUnit
  4. »
  5. org.junit
  6. »
  7. Assert
  8. »
  9. assertEquals
  10. »
  11. AssertionError

java.langAssertionError errorsJUnit

Top patterns

  1. Assert.assertEquals() has thrown an AssertionError
    No solution
  2. Assert.assertEquals() has thrown an AssertionError
    No solution
  3. JUnit "equals" comparison failed

    ComparisonFailure is thrown when using JUnit's internal assertions to compare two strings, number or objects that are not equal. The simplest code to reproduce the error is the following:

    import static org.junit.Assert.assertEquals;
    
    public class ObjectComparisonTest { 
    
       @Test 
       public void shouldAssertStrings() { 
          assertEquals("Jhon", "John");  //The letters are in different order
       } 
    
       @Test 
       public void shouldAssertNumbers() { 
          assertEquals(1, 2); 
       } 
    
       @Test 
       public void shouldAssertObjects() {
          Person p1 = new Person();
          Person p2 = new Person();
          assertEquals(p1, p2);  // The object instances are not the same
       } 
    }
    
    class Person { ... }
    

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

DescriptionException TypeEntry MethodWeb pages

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
2 frames hidden
org.junit.Assert.assertEquals
1746Web pages
AssertionErrorAssert.assertEquals()1746

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
3 frames hidden
org.junit.Assert.assertEquals
1508Web pages
AssertionErrorAssert.assertEquals()1508

JUnit "equals" comparison failed

org.junit.ComparisonFailure
org.junit.Assert.assertEquals
658Web pages
1Solution
ComparisonFailureAssert.assertEquals()658

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
4 frames hidden
org.junit.Assert.assertEquals
542Web pages
AssertionErrorAssert.assertEquals()542

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
2 frames hidden
org.junit.Assert.assertEquals
7Web pages
AssertionErrorAssert.assertEquals()7

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
2 frames hidden
org.junit.Assert.assertEquals
3Web pages
AssertionErrorAssert.assertEquals()3

Assert.assertEquals() has thrown an AssertionError

java.lang.AssertionError
3 frames hidden
org.junit.Assert.assertEquals
2Web pages
AssertionErrorAssert.assertEquals()2