Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7904072

Fail for arrays in JUnit assert[Not]Equals methods

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • jtreg8.1
    • None
    • tools
    • None
    • Cause Known

      JUnit offers assertEquals and assertNotEquals methods that delegate to a "obj1.equals(obj2)" call. JUnit also offers assertArraysEquals methods to deep-compare arrays. JUnit does not offer assertArrayNotEquals methods, though.

      TestNG special-cases assertEquals; for assertNotEquals(Object, Object), there's a runtime check for arrays: https://github.com/testng-team/testng/blob/d50b2ad2d6809d52131a07071fe229b1b901e08c/testng-asserts/src/main/java/org/testng/Assert.java#L2201

      When converting tests from TestNG to JUnit, assertNotEquals in JUnit will not throw if two instances of arrays with the same content are passed into it. It fails on the TestNG line:
      ```
              Object a1 = new int[] {1};
              Object a2 = new int[] {1};
              org.junit.jupiter.api.Assertions.assertNotEquals(a1, a2);
              org.testng.Assert.assertNotEquals(a1, a2);
      ```
      Related: https://github.com/junit-team/junit-framework/pull/4899

      JTReg should therefore throw an error for when arrays are used in JUnit assert[Not]Equals(Object, Object) methods.

            cstein Christian Stein
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: