Why think unit tests should be in their own source code hierarchy instead of side-by-side

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Mar 24 01:15:46 UTC 2018


On Saturday, March 24, 2018 00:51:07 Tony via Digitalmars-d-announce wrote:
> On Saturday, 24 March 2018 at 00:12:23 UTC, Jonathan M Davis
>
> wrote:
> > On Friday, March 23, 2018 22:42:34 Tony via
> >
> > Digitalmars-d-announce wrote:
> >> On Friday, 23 March 2018 at 22:32:50 UTC, H. S. Teoh wrote:
> >> > On Fri, Mar 23, 2018 at 09:45:33PM +0000, Tony via
> >> >
> >> > Digitalmars-d-announce wrote:
> >> >> On Friday, 23 March 2018 at 20:43:15 UTC, H. S. Teoh wrote:
> >> >> > On Friday, 23 March 2018 at 19:56:03 UTC, Steven
> >> >> >
> >> >> > Schveighoffer wrote:
> >> >> > > I've worked on a project where the testing was separated
> >> >> > > from the code, and it was a liability IMO. Things would
> >> >> > > get missed and not tested properly.
> >> >>
> >> >> That's where Test Driven Development comes in.
> >> >
> >> > That's not an option when you have an existing codebase that
> >> > you have to work with.  You basically have to start out with
> >> > tons of code and no tests, and incrementally add them.
> >> > Having to also maintain a separate test tree mirroring the
> >> > source tree is simply far too much overhead to be worth the
> >> > effort.
> >>
> >> I think that you could "Test Driven Develop" the code you are
> >> adding or changing.
> >
> > Insisting on writing the tests before writing the code doesn't
> > help with the kind of situation that H. S. Teoh is describing.
> > And arguably it exacerbates the problem. Regardless, it doesn't
> > help when the code has already been written.
>
> I don't see how it exacerbates it and I don't see how it doesn't
> help. The point of Test-Driven Development it to make sure you
> have written a test for all your code. You can also do
> test-driven development in unittest blocks.

TDD makes it worse, because when you do TDD, you're constantly hopping
between your code and the tests instead of just writing the code and then
writing the tests. That still involves some back and forth, but it avoids
having to hop back and forth while you're still designing the function,
whereas with TDD, you have to go change the tests any time you change the
function before the function is even done. But whatever. If you prefer TDD,
then use it. A number of us have nothing good to say about TDD. You'd pretty
much have to hold a gun to my head before I'd ever do anything along those
lines. I'm all for writing tests, but I hate TDD.

Regardless, having the tests right next to the functions reduces how much
hopping around you have to do to edit the code and tests, because you have
everything in one place instead of in separate files.

> But as far as whether or not it can be done with maintenance
> code, my original reply that mentioned it was to someone who
> appeared to be talking about a new project not getting everything
> tested, not a maintenance project. So saying "can't do it for
> maintenance" doesn't even apply to my reply.

You were replying to H. S. Teoh talking about adding tests to an existing
project, in which case, it's very much about maintenance.

- Jonathan M Davis



More information about the Digitalmars-d-announce mailing list