Old file - New tests

Photo by RetroSupply on Unsplash

Old file - New tests

A recurring TDD dilemma

I am a fervent supporter of TDD (and automated tests). I am certain they make me less error-prone and faster.

But, I face a recurring dilemma with objects that exist in the codebase but are not tested.

When changing a detail of their implementation, my first instinct is to create a test for that detail and then work in the usual TDD loop.

But, what if that detail is in a private method? I need to instantiate the object, and that unit test might give the impression that the whole object is tested when in fact, I am just testing a detail.

In those cases, an interesting dilemma presents itself to me:

  • should I test the whole object? (and thus go into a rabbit hole of unknown duration)

  • Should I test the detail? (accepting the risk of giving someone false reassurance)

  • Should I forego automatic tests for this modification?

I face this dilemma more than I would like, and to be honest... I don't know what the answer is.

What is your normal answer to this dilemma?