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 MemorySizeTest.testUnitConversion to Parameterized Test #3450

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

Monilnarang
Copy link
Contributor

@Monilnarang Monilnarang commented Feb 28, 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?

  • In the test testUnitConversion of class MemorySizeTest the same order of method calls (getBytes, getKibiBytes, getMebiBytes, . . . ) are repeated multiple times with different inputs, making the test harder to maintain and extend.
  • Multiple such clusters of the above method calls are cluttered together in one test, blurring the exact scope of this test.
  • When a test fails, JUnit only shows which assertion failed, but not which specific input caused the failure.
  • Adding new test cases requires copying and pasting the whole block instead of simply adding new data.

Brief change log

Parameterized testUnitConversion
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 before changes:
Screenshot 2025-02-28 at 1 45 20 PM

Test Run report after changes:
Screenshot 2025-02-28 at 1 45 50 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)

@klion26
Copy link
Member

klion26 commented Mar 3, 2025

@Monilnarang thanks for the contribution, seems there are some checkstyle problems in the change, could you please have a look at it.

@zhoujinsong
Copy link
Contributor

You can run mvn spotless:apply command under the root folder of this project to fix the checkstyle issue.

Copy link
Member

@klion26 klion26 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, LGTM

@zhoujinsong zhoujinsong merged commit b19463b into apache:master Mar 4, 2025
4 checks passed
@zhoujinsong
Copy link
Contributor

Thanks for the work! @Monilnarang
Thanks for the review! @klion26

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.

3 participants