0

When (unit) testing, is is bad to expect the code to use certain paths.

For example, should I be testing for specifically "/build/static/public/css/", or just that server.cssPath has been set to a string and is a valid path?

I'm testing a web server.

  • what kind of application are you testing? – gnat Jan 11 '15 at 18:58
  • 1
    @gnat, I updated the question. – Ari Porad Jan 11 '15 at 19:00
  • There is a distinction between "white-box" testing that knows about implementation details, and "black-box" testing that only worries about the functionality you're trying to implement. If that's what you're thinking of, both are considered valid as far as I know. – Ixrec Jan 11 '15 at 19:14
  • @Ixrec, Thanks! Is one considered "better"? – Ari Porad Jan 11 '15 at 19:34
  • Black-box is better for unit testing, when you want to ensure your functionality/API remains stable. White-box is better for regression testing, when you want to ensure specific bugs or other issues you've seen in the past don't come back. If I had to pick only one, it'd probably be black-box, but again it depends on your goals and what difficulties you expect to have. – Ixrec Jan 11 '15 at 19:39
1

Is the path statically or dynamically generated?

If it is dynamic, then you can maybe test for a specific path because there is importance in testing the calculation of the path. I like to reference the same string constants the app uses when possible - that's one way to help.

But if it's static, well - what are you really getting by testing? I think then you care more about the "qualities" of the path, not the value - is it assigned, does the path exist, etc.

About the only exception I've seen to this is if a path is really, really important and that changing it in one place will unexpectedly break something else (bad!) - then it's a warning to others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.