148 reputation
5
bio website
location
age
visits member for 3 years, 11 months
seen Dec 8 at 12:37

Jan
5
awarded  Teacher
Jan
4
answered Is it necessary to add the default case while using switch cases?
Jul
3
awarded  Scholar
Jul
3
accepted DRY, string, and unit testing
Jul
2
comment DRY, string, and unit testing
I like your answer. I agree that the fact that we use a constant is an implementation detail and if you treat it as such, you should ignore it in your unit test. However, given that you are 'omniscient' about the code when you write unit tests, sometimes it's not obvious to see what is only an implementation detail and what matters.
Jul
1
revised DRY, string, and unit testing
Fixing typo in first code example
Jul
1
awarded  Editor
Jul
1
revised DRY, string, and unit testing
Modifying example to (try to) make point clearer
Jul
1
comment DRY, string, and unit testing
I like the idea of testing the constant separately. That is what I often do: I write a test that interpolates my template and makes sure I get the expected output. After that, I use the constant in my other unit tests.
Jul
1
comment DRY, string, and unit testing
Thanks for the answer. I think I made my example too simple though. I don't really want to make sure the interpolation works. I am more thinking of a case where foo would do more things and as part of generating its output, use a constant I have defined. I would then need to check that somewhere, the returned value contains the right string. I will figure a better example.
Jul
1
awarded  Student
Jul
1
comment DRY, string, and unit testing
My example is simple to stupidity which probably doesn't help my point. I'm thinking of the case where my foo would do other things and at some stage use the string constant to produce it's output. How would I check that the output contains the value of the constant?
Jul
1
asked DRY, string, and unit testing
Jun
20
awarded  Supporter