8
rudilee
3y

I've been writing unit tests for an existing project for a couple of months now. I'm not experienced at automated tests, so I'm not sure what's good unit tests supposed to be, but the unit tests that I wrote basically just confirm the flow that already implemented, which to my limited understanding of unit tests is supposed to be the other way around. The good thing is that I could catch some minor problems with the implementation such as not imported class used, the wrong variable used since the project is a rewrite of legacy code so a lot of copy-pasta, I also have to wrap some part of the code that interacts with the filesystem in a DI class so I could test that part.

Comments
  • 3
    Adding unit tests to existing code can be quite tricky. You should aim to cover the existing flow, as you are doing, but try to also identify possible error states, edge cases, etc and add tests.

    The main advantage of adding tests to existing code is to verify and modifications made later. Indeed it is one of the key steps in working with legacy code.
Add Comment