From: Nicholas Van Weerdenburg Date: 2005-12-22T09:31:17+09:00 Subject: Re: unit tests == ugly code? ------=_Part_28328_31625671.1135211465829 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline That's interesting. On of the TDD pitches is that the tests present a constant design pressure on the code encouraging refactoring as you go, the theory being bad code isn't so testable. My experience is limited, but I find this mostly true, and it helps me name things since I'm writing code to a much clearer context then if I'm just coding "in the wild" so to speak. e.g. def test_list_archived_articles a=3DArticle.find_by_status "old" # test here end My test to check if my list articles works shows some strange semantics, an= d I rewrite as: def test_list_archived_articles articles =3D Article.get_archived # test here end and I update Article to encapsulate how archiving is implemented. If you are writing tests and not refactoring, I think you are missing a mai= n point of TDD- design rather then QA. Also, without the refactoring, your tests would likely become stranger as your project gets bigger, getting to the point where you can't figure out how to effectively test new features. At least that's the theory. Regards, Nick On 12/21/05, Joe Van Dyk wrote: > > I've found that when I write the tests first, and then write the code, > I'm not very concerned about what the code looks like. When the code > passes the test, I drink a beer and party, then move on to the next > test. > > In practice, this means that I'm using a lot of ugly regex's, poorly > named variables, and so on. I'd be more concerned about the > readability of the code if there wasn't unit tests behind it. I'm > generally in a rush to finish whatever I'm doing, and figure that > since I have a bunch of tests, refactoring stuff later won't be a big > deal. > > Anyone else out there like me? Or should I be anal about writing good > code even with the tests? I guess that would be ideal, but I'd rather > get the functionality done first. > > Joe > ------=_Part_28328_31625671.1135211465829--