Java Interview Test

This morning in a working interview, they asked me if I had some old code without any tests, and I need to change something, how would I do to completely make sure that I am not violating anything.

My answer was, first of all, I would create a test for the part of the code that I need to change, and then, as soon as the test passes, I will modify the code to ensure that the test still passes. Thus, basically this is done from a test-based approach. I have not seen that the one who talked very well with myanswer would like you to have your opinion on subjects, is there a better approach for this?

Is my answer really?

Many thanks

+4
source share
1 answer

Your answer is correct, but perhaps too simplistic.

In the real world, as a rule, this is not so simple. Especially for legacy systems where a lot of code is connected too much, there are bad abstractions, inefficient language constructs, etc. It is especially difficult if there are no other tests and this happens.

Also, sometimes it’s just not easy to mock dependencies if they are hard-coded. Then it depends on the mocking capabilities of the framework, if it allows you to mock the final classes, static methods, etc.

It may be worth mentioning a few templates from the book "Working Effectively with Legacy Code."

+2
source

All Articles