James Raitsev
James Raitsev

Reputation: 96391

How to refactor test code together with production code?

Suppose you start with an auto-generated method

public void setKey(Key key) {
    this.key = key;
}

And write a test for it

@Test
public void testSetKey() 

Then 3 month from now you decide that a more appropriate name for the method would be changeKeyTo. You refactor your production code and end up with:

public void changeKeyTo(Key key) {
    this.key = key;
}

Life is good, however, your test name remained unchanged

@Test
public void testSetKey() 

How do you deal with something like this? Can you refactor test code automatically with your production code? Does eclipse allow this?

Upvotes: 5

Views: 389

Answers (2)

Péter Török
Péter Török

Reputation: 116266

Most IDEs with automatic refactoring support will also rename the calls to your method from test code (if you keep your test code in the same project so that the IDE can see it). IIRC Eclipse was able to do that too, the last time I used it. IntelliJ, which I am using now, does it.

Upvotes: 0

GingerHead
GingerHead

Reputation: 8230

eclipse would not figure this out to change: It only changes the references of the method used in other classes or in the same class.
If you really want to make this functionality work, you could extend eclipse's refactoring API as I did for my project and give it this new functionality.
If you like to have any references on this just ask me ;-)

Upvotes: 1

Related Questions