DEV Community

Discussion on: Don't use non-test constants in unit tests

Collapse
 
mentallurg profile image
mentallurg

A good post. When I'm implementing tests, I'm always trying to avoid any dependency on the code under test or to keep it as little as possible. Sometimes it is easier, e.g. when testing a web service or REST service. Sometimes it is not, e.g. when implementing unit tests or integration tests.

I'm trying not to use not only constants, but also any utilities the code under test depends on. The price is some code duplication. But to me it is more important that the dependency is reduced and thus the probability to find bugs increases.

And when I keep sometimes more dependency, it is not because I believe it does not affect the test, but because otherwise the implementation of the test or its maintenance would be too expensive.

Collapse
 
scottshipp profile image
scottshipp

Sounds like a great pragmatic approach!