← Back to Upcase

Test Drive Process to Remove a Feature


(Luke Bacon) #1

The ‘red, green, refactor’ process for adding new features through test driven development (TDD) is much discussed, but I’ve found it hard to find discussion of an approach to removing a feature.

When I’m removing code, I really want to know how that’s going to effect the application over all—so starting with good integration test coverage seems essential.

Two approaches come to mind:

Approach A

  1. Remove the implementation code of the feature, tests for the feature go Red.
  2. Remove the tests of the feature

Approach B

  1. Adapt the integration tests for the feature to reflect it not existing, e.g. the button you were going to click doesn’t exist.
  2. Now you’ve got red tests
  3. Remove the feature implementation code, making the tests green.
  4. You’ve probably now got Red unit tests for the model etc. . remove the unit tests that should be showing ‘unknown method’, or uninitialized Constant’ errors.
  5. All tests should now be green.
  6. Remove the tests that check the non-existence of the feature.

I feel like Approach B is closer to a traditional TDD path, and feels safer.

I’ve just come in to quite a complex project and my first task is to remove a feature. The test coverage is pretty good, and I’m trying to think through the best way to remove code safely.

How have you handled this process?

Does anyone know of good writing about this situation?

Thanks for your great discussion as always :slight_smile:

Luke


(Orlando Del Aguila) #2

I like to follow the Approach A. If everything is correct, the test suite should be red, if It’s green, I cry a little on the inside and then I dive to understand the code and add some tests.


(Luke Bacon) #3

Thanks @orlando , I recon I was over thinking this a bit.

I ended up going with a combination of the two, trying to break down removing something into small parts of improving coverage as I went.

The application is lacking comprehensive integration tests. I think I’ve re-learned how critical they are for the confidence of developers first viewing an application :slight_smile: