a7omiton
a7omiton

Reputation: 1617

Should you make tests for constants?

I'd like to know if there is any value in providing a test to say that a constant equals x in my test suite.

A couple of benefits I see to doing it:

Would that be beneficial or just a nuisance?

Upvotes: 1

Views: 239

Answers (1)

piotrek
piotrek

Reputation: 14550

imho, there is no benefit in it.

  • if dev see failed tests because of a constant then he will simply update the same value in tests. so it's not a benefit, it's a duplication
  • you should have tests for the code that uses the constant. if not unit tests then integration tests (e.g. address of the mail server) those tests should fail if something is wrong with the constant

the only tests for constant i can imagine is when your constant is some complex object then maybe you can tests if all required constraints between its properties are met. but if it's just, let's say, a number or string then, imho, it's just a waste of time because test maintenance costs and it gives you absolutely no additional security

Upvotes: 2

Related Questions