you're right. But testing bad code is really really hard. So usually tested code is somewhat better overall, just because it's the easiest way to do it.
If you develop the tests along with the main code, it's usually less painful, except if there's a hunk of legacy code to integrate your new one with. Ok, this is probably the case for most developers...
As opposed to the alternative, which is dealing with technical dept, spaghetti, legacy code, etc...