back

by jader201·14y ago·view on hn ↗
> For a lark I'm going to take an old project that has been running for years without a hitch and I'm going to retro-actively add tests to the code.

Be prepared to possibly rewrite most, if not all, of your code. I have found, at least in my old code -- which admittedly was written well before I became familiar with the concept and discipline of testing -- that my code is just not testable. At all.

It is very tightly coupled, and against which is almost impossible to write any sort of meaningful tests.

But maybe you were a better designer than I was, and if so, you may be able to fairly easily add tests to your code.

But if not, you're in for a challenge. :)

1 comments
If your code has been "running without a hitch" and "an old project" (which I assume means you are no longer actively updating it) why are you adding tests?

Out of curiosity, what's the ROI that you see in adding tests to that project?

For some reason clients tend to get upset when things that were working suddenly break (they don't even care if it as legacy code base!).

Joking aside, in order to effectively prevent that, a test suite must be in place to prevent regressions when you change/add code. If there isn't one, you need to decide between cranky clients or the nastyness of adding test to legacy code.

> For some reason clients tend to get upset when things that were working suddenly break (they don't even care if it as legacy code base!).

Another sad truth to consider is that just the process of refactoring your code to add tests can just as easily break functionality. I've learned this the hard way.

> (which I assume means you are no longer actively updating it)

I believe __abc was basing his comment off the assumption that the code wasn't being actively developed, which significantly reduces the ROI of adding tests to an existing project.

Sounds like it's more back to the OP's response below, that it's an exercise in learning.

I think the author is looking at it as more of an experiment than a valuable project with a positive ROI. As jader201 said he will probably discover that it's a pretty tough thing to do when the code wasn't written with testing in mind. I also believe he will find issues exposing parts of his code to be tested.
To learn.