Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a TDD test for removing a field from a Java class?

Tags:

java

tdd

I have a Java class with three fields. I realized I only need two of them due to changes in requirements.

Ideally I'd write a failing test case before modifying code.

Is there a standard way, or should I just ignore TDD for this task?

like image 338
Roger C S Wernersson Avatar asked Jan 24 '26 21:01

Roger C S Wernersson


1 Answers

That's refactoring, so you don't need to start with failing tests.

  1. Find all the methods using the field.
  2. Make sure that they're covered by unit tests.
  3. Refactor the methods so they no longer use the field.
  4. Remove the field.
  5. Ensure that the tests are running.
like image 60
bereal Avatar answered Jan 27 '26 11:01

bereal