Hacker News new | ask | show | jobs
by yuchi 1641 days ago
If the project you are working on has enough time to burn, and the codebase has no (or near to) unit tests, add them.

Find large utilities that are not coupled with a particular part of the application, and put them under heavy testing. Do not fix any failing test before having completed the test suite.

If you have access to other developers that know the codebase, review the tests with them, and fix failing tests together.

Do the same for the frontend / interface code, but do not go for unit testing imho, go for visual regression testing.

And the end of the process you will have a very large knowledge of the codebase, and you will have improved it at the same time.

1 comments

How are you supposed to write tests for code if you don't understand what it does/is supposed to do?
You can create regression tests that prove that the code does what it does today - which helps you understand it, provides a readable description of what it does and protects against regression bugs in the future.

Here's a relevant trick I frequently use for this kind of work with Python: https://simonwillison.net/2020/Feb/11/cheating-at-unit-tests...

First of all you’re not going to be all by yourself. Ask previous developers or peers if there are any. Ask them to help you navigate the codebase and find good candidates.

On the opposite scenario, where you have to take ownership of a large codebase and there’s no one around that can guide you through it, if every time you learn something about it you turn it into a test case you will do your future self a favor and at the same time also tracing your progress.