I've found the best way to achieve that is to force the agent to do TDD. Better to get it to do Outside-in TDD. Even better to get it to run Outside-in TDD, then use mutation testing to ensure it has fully covered the logic.
I've written about this and have a POC here for those interested: https://www.joegaebel.com/articles/principled-agentic-softwa...