A good way to get written tests is to increase accountability. If a developer needs to explain to someone else why they did not write unit tests, they will most likely do it. Most of the companies I worked with demanded that any proposed fixes to the trunk be reviewed by another developer before the commit, and that the name of the reviewer be included in the commit comments. In this environment, you can tell your team that they should not allow the code to โpassโ peer-to-peer code if unit tests are not performed.
You now have a chain of responsibility. If a developer commits a code without calling a reviewer, you can ask them who looked at the code (and since I learned the hard way, I should say โnoโ to your boss when this question was asked, this is not fun!). If you become aware that the code is passed without unit tests, you can ask both the developer and the code reviewer why unit tests were not included. The ability to ask this question encourages code reviewers to insist on unit tests.
Another step you can take is to set commit commit in your version control system, which sends an email to the whole team when commit is committed, along with files and even the code that made the commit. This provides a high level of transparency and further encourages developers to "follow the rules." Of course, this only works if it is scaled to the amount your team commits per day.
This is more a psychological solution than a technical solution, but it worked well for me in managing software teams. It is also a bit softer than the rubber hose suggested in another answer. :-)
MattK source share