Skip to content

test: Refactored testSetCodeAndMsgUpdatesValuesCorrectly to use parameterized unit testing #7288

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

Open
wants to merge 10 commits into
base: 2.x
Choose a base branch
from

Conversation

Monilnarang
Copy link
Contributor

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

Summary:

  • Parameterized testSetCodeAndMsgUpdatesValuesCorrectly and added more test cases.

Elaboration:

  • The same method calls (getCode & getMsg()) would be repeated multiple times with different inputs, making the test harder to maintain and extend.
  • 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 another Assertions.assertEquals(...) statement instead of simply adding new data.

To accomplish this, I have retrofitted the test into a parameterized unit test. 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 execution results after changes:
Screenshot 2025-04-13 at 11 32 37 AM

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Successful tests run

Ⅴ. Special notes for reviews

Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.51%. Comparing base (8c72b89) to head (e501b3b).

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7288      +/-   ##
============================================
- Coverage     54.52%   54.51%   -0.01%     
  Complexity     7303     7303              
============================================
  Files          1178     1178              
  Lines         41962    41962              
  Branches       4923     4923              
============================================
- Hits          22878    22874       -4     
- Misses        16914    16923       +9     
+ Partials       2170     2165       -5     

see 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

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

LGTM

@slievrly
Copy link
Member

@Monilnarang Could you resolve all the conflicts of the PRS you submitted?

@Monilnarang
Copy link
Contributor Author

Thanks for the review @slievrly.
Resolved the conflicts.

Comment on lines +61 to +62
code.setCode(newCode);
code.setMsg(newMsg);
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, Enums are generally used for immutable objects.
If we use a setter on something like Code.SUCCESS as shown in the code below—setting it to 500 and Server error—it can create confusion for developers.

Code success = Code.SUCCESS;
success.setCode("500");
success.setMsg("Server error");

Therefore, while it's not directly related to this PR, I think it would be better to remove the setter from Code in a separate PR.

@xingfudeshi What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants