Your mentee is three weeks into a new job and full of energy. The main service has almost no tests. Deployments are done carefully, on a Thursday, with someone watching the logs. They have already drafted a plan to add tests everywhere, introduce a new framework and make test coverage a required check. They want your opinion before they present it to the team on Monday.
Admire the energy first, out loud. Then help them slow down, because a plan like this, from someone three weeks in, usually lands as criticism of everyone who built the system.
Start with curiosity. Ask what they know about why there are no tests. Often the reasons are ordinary. The code was written in a hurry by two people for a deadline, or it is hard to test because everything talks to the database directly. Those reasons matter, because they tell you where to begin.
Then give them a better first move. In his 2004 book Working Effectively with Legacy Code, Michael Feathers defines legacy code simply as code without tests, and describes a technique called characterization tests. Instead of writing tests for what the code should do, you write tests that record what it actually does today, odd behaviour included. They do not judge the code. They protect it, so the next change cannot quietly alter something people rely on.
Suggest they pick the next piece of code they genuinely need to change for a ticket, and add a few characterization tests around that one spot before touching it. Then make the change. Then mention in the pull request what the tests caught or confirmed. One real example does more than any proposal.
Help them notice the team's feelings too. The people who kept this system running without tests have skills your mentee does not have yet, such as knowing which parts are dangerous. Encourage them to ask those people which area worries them most, and start there.
And suggest they save the big plan. If, after a couple of months, the small tests keep paying off, the team may well ask for a wider approach. At that point your mentee will be the obvious person to lead it, because they will have shown it working instead of describing it.
– Asael Shinder
