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

[Improvement]: Refactored test testToHumanReadableString of MemorySizeTest to paramerterized #3454

Merged
merged 2 commits into from
Mar 5, 2025

Conversation

Monilnarang
Copy link
Contributor

@Monilnarang Monilnarang commented Mar 5, 2025

Aim:

Improve the test code by avoiding code duplication, improving maintainability, and enhancing readability. By converting the test into a parameterized unit test, we reduce boilerplate code, make it easier to extend by simply adding new input values, and improve debugging by clearly identifying which test case fails instead of searching through individual assertions.

Why are the changes needed?

  • The same method call to toHumanReadableString is repeated multiple times with different inputs in the test testToHumanReadableString making it harder to maintain and extend.
  • When this test fails, JUnit only shows which type of assertion failed, but not which specific input caused the failure.
  • Adding new test cases requires copying and pasting new assertion instead of simply adding new data.

Brief change log

Parameterized the test testToHumanReadableString using @MethodSource. This reduces duplication, allows easy extension by simply adding new value sets, and makes debugging easier as it clearly indicates which test failed instead of requiring a search through individual assertions.

Test run report after change:
Screenshot 2025-03-04 at 7 16 39 PM

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible

  • Add screenshots for manual tests if appropriate

  • Run test locally before making a pull request

Documentation

  • Does this pull request introduce a new feature? (yes / no)
    No
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

Copy link
Contributor

@zhoujinsong zhoujinsong left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks for the contribution!

@zhoujinsong zhoujinsong merged commit 0cc8160 into apache:master Mar 5, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants