If you write tests as you go, you will build on top of a working foundation. Don’t waste time debugging broken functions.
Tests will allow you to Make it work, then make it better. You will be able to refactor that crap code into something better knowing the functionality still the same.
This is a deep topic, and learning ways to automate testing your shit is a skill that all engineers should master.
You can use techniques like Behaviour-Driven Development or Test-Driven Development, or you can write tests after you implement something. The technique doesn’t matter; what matters is that your code is working and that you are validating that it is working.
AI is excellent at writing tests for you. AI coding warning
And don’t forget that, even with 90% test coverage, you should Manually test your contributions.
Part of Tips for Software Engineers