The main problem with your idea is that you can't just write tests for any code. The code has to be testable.
Ie. you need to be able to inject mocks, separate out the bit you want to test, access state which is changed and needs confirming etc.
Unless you get lucky or write the test first, chances are writing the test means rewriting the code a bit.