question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

changes in behavior with assertEquals(Collection) et al

See original GitHub issue

TestNG Version

7.4.0

Expected behavior

assertEquals(Collection c1, Collection c2) is documented to compare the collections in the same order. It no longer does.

Actual behavior

assertEquals(Collection c1, Collection c2) now delegates to c1’s equals() implementation via Objects.equals(), which can give different behavior behavior from earlier releases (e.g., 7.3.0).

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

The following test fails on 7.3.0, as expected. However, it passes on 7.4.0 and on the testng-7.5.0-20210505.072953-25.jar snapshot, which is an unexpected change in behavior.

This was introduced by #2460, which changed a bunch of occurrences of actual == expected to Objects.equals(actual, expected). This resulted in silent changes of behavior. Some of this was fixed by #2487, which reverted the test back to actual == expected for assertSame and assertNotSame. I believe however that the changes in #2460 were ill-considered, as they potentially changed the behavior of several different cases. The example with assertEquals(Collection, Collection) is just one that I happened to notice. There are likely other behavior changes that resulted from #2460.

The #2460 change resulted in bugs in OpenJDK, among them https://bugs.openjdk.java.net/browse/JDK-8266780. This particular one was fixed by #2487. However, I’m concerned that even if we don’t see other test failures, that we will now be testing something different from what we had expected to test when the test was written. This is a matter of great concern.

I note that the documentation for assertEquals(Collection, Collection) still says “Asserts that two collections contain the same elements in the same order” so the implementation now disagrees with the documentation.

import org.testng.annotations.Test;
import static org.testng.Assert.*;

import java.util.*;

@Test
public class AssertEqualsCollection {
    public void checkEquals() {
        Collection<String> set1 = new LinkedHashSet<>();
        Collection<String> set2 = new LinkedHashSet<>();

        set1.addAll(Arrays.asList("a", "b", "c"));
        set2.addAll(Arrays.asList("a", "c", "b"));

        assertEquals(set1, set2);
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
stuart-markscommented, Jun 25, 2021

(oops, missed this)

I’m somewhat doubtful about whether OpenJDK can try out new versions of TestNG effectively. The jtreg thing is a mostly single-purpose framework which is only for testing the JDK. I doubt it’s worth your time to try to build and run it. The integration work between jtreg and TestNG requires some coding work, I believe; it’s more than a matter of dropping another jar file on the classpath. As a result we upgrade the TestNG version in jtreg only once a year or so. However, I’ll ask about this to see if it’s feasible.

My recommendation for the TestNG team is to think of the API “documentation” as more of a specification and to consider the unit tests for the TestNG APIs to be more like a conformance test suite, which tests conformance of the implementation against the specification. (This is of course colored by my work on Java and the JDK, which has a similar structure.) While there’s only one implementation of TestNG, applying more rigor by thinking of things as specifications and conformance tests seems appropriate for something as fundamental as a test suite.

0reactions
vlsicommented, Jun 14, 2021

@stuart-marks , hi there. Do you think it is feasible to run testng test subset in cbeust/testng GitHub Actions to validate that upcoming TestNG releases do not break OpenJDK builds? Does it sound like “build https://github.com/openjdk/jtreg with the latest testng”, and “run the resulting testng over the latest openjdk”? Do you have suggested jtreg commands (or references?)? (I have never actually ran jtreg yet)

Of course, it won’t address hidden issues like “unexpected tests that should fail but that actually passes”, however, running OpenJDK before TestNG release would definitely be an improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Please change assertEquals(Collection, Collection)
After a lot of debugging and finally reading the TestNG JavaDoc I think the implementation is wrong and should be replaced. Reasons: 1...
Read more >
arXiv:1902.08482v3 [cs.SE] 16 Dec 2019
In this paper, we propose an approach that detects behavioral changes in commits. As input, it takes a program, its test suite, and...
Read more >
2020 Peilun Zhang - Darko Marinov's Research Group at UIUC
The goal of this thesis is to propose automated code changes that help ... that it “Returns an array of Field objects reflecting...
Read more >
AssertJ - fluent assertions java library - GitHub Pages
You can assert that all or any elements verify the given assertions with ... it is possible to change that behavior by calling...
Read more >
A time of change: Behavioral and neural correlates of ... - NCBI
Adolescence is a developmental period that entails substantial changes in affective and incentive-seeking behavior relative to both ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found