Monilnarang opened a new pull request, #7160: URL: https://github.com/apache/incubator-seata/pull/7160
- [ ] I have registered the PR [changes](../changes). ### Ⅰ. Describe what this PR did 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. ``` @Test void getOrDefault() { Assertions.assertEquals("Value", lowerCaseLinkHashMap.getOrDefault("Key", "abc")); Assertions.assertEquals("Value", lowerCaseLinkHashMap.getOrDefault("key", "abc")); Assertions.assertEquals("abc", lowerCaseLinkHashMap.getOrDefault("default", "abc")); } ``` In the above in tests from LowerCaseLinkHashMapTest.java: * The same method call (lowerCaseLinkHashMap.getOrDefault) is 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. ### Ⅱ. 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 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org