Reputation: 9426
Wikipedia's article on Magic Numbers suggests that any constant should be assigned to a variable with a meaningful name.
Does the same practice apply to HTTP status codes, which are a well-defined standard? That is, when writing tests, should one do assert response.status_code == HTTP_STATUS_CODE_SUCCESS
or is assert response.status_code == 200
appropriate in this context?
Upvotes: 9
Views: 1523
Reputation: 1959
Using a constant you defined is a good idea. Using one defined by the language is a better idea. I'm not sure what language you are using but most languages have one. Java C# python
Upvotes: 7
Reputation: 700800
Yes, magic numbers are magic numbers even if they are well known and well documented.
Upvotes: 2