JUnit "equals" comparison failed

Thrown when an {@link org.junit.Assert#assertEquals(Object, Object) assertEquals(String, String)} fails. Create and throw a ComparisonFailure manually if you want to show users the difference between two complex strings.

Inspired by a patch from Alex Chaffee (alex@purpletech.com) @since 4.0
at org.junit.Assert.assertEquals

Typical Exception Messages

  1. <No message>
  2. expected:<[]OVERRIDDEN> but was:<[NON ]OVERRIDDEN>
  3. expected:<[1]> but was:<[0]>
  4. expected:<[success]> but was:<[failed]>
  5. expected:<<memory:[8192, vCores:8]>> but was:<<memory:[4096, vCores:4]>>
  6. expected:<[NON ]OVERRIDDEN> but was:<[]OVERRIDDEN>
  7. expected:<[h2]> but was:<[undefined]>
  8. expected:<[undefined]> but was:<[Test-Product]>
  9. expected:<[localhost]:12345> but was:<[]:12345>
  10. expected:<gradle is gr[8]> but was:<gradle is gr[eat]>

Specific cases


igorski, 4 months ago

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 { 

   public void shouldAssertStrings() { 
      assertEquals("Jhon", "John");  //The letters are in different order

   public void shouldAssertNumbers() { 
      assertEquals(1, 2); 

   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.

External results for this pattern (661)

  1. ttsugriyvia GitHub4 weeks ago
    Stub for com/example/buck/A.class is not correct expected:<...tation;() : FIELD, 0[] // invisible // ...> but was:<...tation;() : FIELD, 0[;] // invisible // ...>
    Show stack trace
  2. codingphilvia GitHub4 weeks ago
    expected:<[1]> but was:<[0]>
    Show stack trace
  3. TikhomirovSergeyvia GitHub1 month ago
    expected:<.[ContactsListActivity]> but was:<.[ApiDemos]>
    Show stack trace
  4. hasancelikvia GitHub1 month ago
    expected:<[LatestUpdatedV]alue2> but was:<[v]alue2>
    Show stack trace
  5. zonghaishangvia GitHub1 month ago
    expected:<... exceeds size limit:[100]> but was:<... exceeds size limit:[ 100, try to specify -M size_limit in your command, check the help command for more.]>
    Show stack trace
  6. Jared Martinvia Google Groups1 month ago
    expected:<[hello world!]> but was:<[Mock for Foo, hashCode: 936146014]>
    Show stack trace
  7. handycccvia GitHub1 month ago
    expected:<[Futur]e-day Pickup> but was:<[Sam]e-day Pickup>
    Show stack trace
  8. tcurdtvia GitHub1 month ago
    unexpected resolve for #!/usr/bin/python3 -B line = line.replace('@ALLOW_BATCH_FILTER@', config[self.client]['ALLOW_BATCH_FILTER']) expected:<..., config[self.client[]['ALLOW_BATCH_FILTER'])]> but was:<..., config[self.client[[]'ALLOW_BATCH_FILTER']) ]>
    Show stack trace
  9. mcomellavia GitHub1 month ago
    for input:a网络A.网络.cn|| expected:<[网络.]cn> but was:<[]cn>
    Show stack trace
  10. julianofischervia GitHub1 month ago
    group_size.ccs.report differs! expected:<... 347 2 8 ... 1794...>
    Show stack trace