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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Monilnarang
Copy link

@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)

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.

1 participant