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:
- Remove the implementation code of the feature, tests for the feature go Red.
- Remove the tests of the feature
- Adapt the integration tests for the feature to reflect it not existing, e.g. the button you were going to click doesn’t exist.
- Now you’ve got red tests
- Remove the feature implementation code, making the tests green.
- 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.
- All tests should now be green.
- 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