[ 
https://issues.apache.org/jira/browse/NET-736?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory closed NET-736.
-------------------------------
    Resolution: Not A Problem

PR closed.

 

> Refactored test in SubnetUtilsTest to use parameterized unit testing to 
> reduce duplication and improve maintainability
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: NET-736
>                 URL: https://issues.apache.org/jira/browse/NET-736
>             Project: Commons Net
>          Issue Type: Improvement
>    Affects Versions: 3.11.1
>            Reporter: Monil Narang
>            Priority: Major
>
> *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.
> {code:java}
> @Test
>     public void testNET641() {
>         assertFalse(new 
> SubnetUtils("192.168.1.0/00").getInfo().isInRange("0.0.0.0"));
>         assertFalse(new 
> SubnetUtils("192.168.1.0/30").getInfo().isInRange("0.0.0.0"));
>         assertFalse(new 
> SubnetUtils("192.168.1.0/31").getInfo().isInRange("0.0.0.0"));
>         assertFalse(new 
> SubnetUtils("192.168.1.0/32").getInfo().isInRange("0.0.0.0"));
>     }
> {code}
> In the above in SubnetUtilsTest.java: 
> 1. The same method call new SubnetUtils(...).getInfo().isInRange(...) is 
> repeated multiple times with different inputs, making the test harder to 
> maintain and extend.
> 2. When a test fails, JUnit only shows which assertion failed, but not which 
> specific input caused the failure. 
> 3. Adding new test cases requires copying and pasting another 
> assertFalse(...) 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to