exupero
exupero

Reputation: 9426

Are HTTP status codes considered "magic numbers"?

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

Answers (2)

Sign
Sign

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

Guffa
Guffa

Reputation: 700800

Yes, magic numbers are magic numbers even if they are well known and well documented.

Upvotes: 2

Related Questions