Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array assertEquals failure message when an element is null or non-null #3136

Merged
merged 2 commits into from
Jun 14, 2024

Conversation

zAlbee
Copy link
Contributor

@zAlbee zAlbee commented Jun 13, 2024

Fixes #3135 - assertEquals on arrays - Failure message is missing information about the array index when an array element is unexpectedly null or non-null.

Just need to use the errorMessage variable instead of message.

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages for assertEquals on arrays to provide clearer information when an array element is unexpectedly null or non-null.
  • Tests

    • Added new test cases to ensure better handling and reporting of array element differences in assertions.

Copy link

coderabbitai bot commented Jun 13, 2024

Walkthrough

The update focuses on enhancing the assertEquals method in the TestNG library to provide more detailed failure messages when comparing arrays. Specifically, it improves the clarity of the messages by indicating the index at which the comparison fails. New test methods have been introduced to verify this enhanced functionality.

Changes

Files Change Summary
CHANGES.txt Added a summary of the changes related to GITHUB-3135 improvement.
.../java/org/testng/Assert.java Updated the parameter name in the assertEquals method to improve clarity.
.../java/org/testng/AssertTest.java Added new test methods to verify the enhanced assertEquals functionality.

Sequence Diagram(s)

Changes are mainly related to improving messages and adding tests. Sequence diagrams are omitted for simplicity.

Assessment against linked issues

Objective Addressed Explanation
Improve assertEquals method to provide detailed failure messages for arrays (GITHUB-3135)
Verify enhanced functionality with new test cases (GITHUB-3135)
Update documentation to reflect the change (assumed from context but not specified in the tasks) Document update not mentioned in changes

Poem

In the world of code so pristine,
TestNG glows with a brighter sheen.
Arrays now fail with clear insight,
Index revealed in assertion's light.
A bunny hops with joy today,
For bugs, we now keep at bay. 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7d35d6 and 6bdf496.

Files selected for processing (3)
  • CHANGES.txt (1 hunks)
  • testng-asserts/src/main/java/org/testng/Assert.java (1 hunks)
  • testng-asserts/src/test/java/org/testng/AssertTest.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • testng-asserts/src/main/java/org/testng/Assert.java
Additional comments not posted (4)
testng-asserts/src/test/java/org/testng/AssertTest.java (3)

358-365: Excellent use of expectedExceptions and expectedExceptionsMessageRegExp to validate the error message format. This aligns well with the PR's objectives to enhance error messages in array assertions.


367-374: Well implemented test to check assertions when expected non-null elements are null. The detailed assertion message validation ensures clarity in error reporting, which is crucial for debugging.


376-383: This test effectively captures the scenario where an expected null element is non-null, ensuring that the failure message accurately reflects the discrepancy at the correct array index.

CHANGES.txt (1)

4-4: Ensure that the description for the fix in the change log is accurate and matches the implemented changes in the PR.

Verification successful

The search results show multiple instances of the failNotEquals method in both AssertJUnit.java and Assert.java. However, the context provided does not clearly indicate any specific changes related to handling array elements and their indices.

To ensure the accuracy of the change log description, it is necessary to further investigate the context around array-specific assertions and see if there are any modifications or additions that handle array elements and their indices.


The additional context around the assertArrayEquals and assertArrayNotEquals methods in Assert.java shows that there are indeed mechanisms in place to handle array assertions and provide detailed messages, including information about array indices.

This matches the description in the change log entry:

Fixed: GITHUB-3135: assertEquals on arrays - Failure message is missing information about the array index when an array element is unexpectedly null or non-null (Albert Choi)

The implementation includes logic to generate detailed error messages that mention array indices when elements do not match, which aligns with the change log description.

  • : The change log description accurately reflects the implemented changes related to array assertions and detailed failure messages.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the accuracy of change log description with the actual code changes.

# Test: Search for the function `failNotEquals` and check the parameter name change.
rg --type java $'failNotEquals'

Length of output: 1993



Script:

#!/bin/bash
# Extract relevant code around `failNotEquals` in `AssertJUnit.java` and `Assert.java` to verify changes.

# Display lines around `failNotEquals` in `AssertJUnit.java`
rg --type java --context 5 'failNotEquals' testng-core/src/main/java/org/testng/AssertJUnit.java

# Display lines around `failNotEquals` in `Assert.java`
rg --type java --context 5 'failNotEquals' testng-asserts/src/main/java/org/testng/Assert.java

Length of output: 6066



Script:

#!/bin/bash
# Further investigate the context around array-specific assertions to verify changes related to array elements and their indices.

# Display lines around `assertArrayEquals` and `assertArrayNotEquals` in `Assert.java`
rg --type java --context 10 'assertArrayEquals|assertArrayNotEquals' testng-asserts/src/main/java/org/testng/Assert.java

Length of output: 2628

@juherr juherr merged commit e0a7d5f into testng-team:master Jun 14, 2024
9 checks passed
@zAlbee zAlbee deleted the array-assert-equals-message branch June 14, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants