Problem:
The Magic Number Test occurs when assert() statements in a test method contain numeric literals (i.e., magic numbers) as parameters.
Solution:
As magic numbers do not indicate the meaning/purpose of the number, they should be replaced with constants or variables, thereby providing a descriptive name for the input.
Before:
assertEquals(200, i.getStatus());
After:
private final int HTTP_STATUS_OK = 200;
assertEquals(HTTP_STATUS_OK, i.getStatus());
This is a test refactoring
Problem: The Magic Number Test occurs when assert() statements in a test method contain numeric literals (i.e., magic numbers) as parameters.
Solution: As magic numbers do not indicate the meaning/purpose of the number, they should be replaced with constants or variables, thereby providing a descriptive name for the input.
Before: assertEquals(200, i.getStatus());
After: private final int HTTP_STATUS_OK = 200; assertEquals(HTTP_STATUS_OK, i.getStatus());