From: Shadowfirebird Date: 2008-08-03T00:53:10+09:00 Subject: Re: unit testing advice I certainly "get" the idea that it's better to write the tests first. Unfortunately my dinosaur brain needed to write some code to prove that my class model was workable...! What I'm seeing quite clearly now, is that the next best thing is writing the tests while *pretending* that you haven't written the code yet. Because the tests should be based on what the code is *supposed* to do, not what it does. Look at the code when you want to know what it does; but when you want to know what it's supposed to do, look inside your head. I suppose you are all going to say that the tests should show what the code is supposed to do? I really like that idea... On Sat, Aug 2, 2008 at 2:31 PM, David A. Black wrote: > Hi -- > > On Sat, 2 Aug 2008, Phlip wrote: > >> David A. Black wrote: >> >>>> - live users >>>> - random numbers >>>> - hardware - networks, robots, tape drives, the clock, etc >>>> - system errors >>>> >>>> If your B object is not on the list, you should not mock it. >>> >>> I wouldn't narrow it down that strictly. It can depend on the purpose >>> of the test, as well as the profile of the thing you're mocking. >> >> You can also avoid mocking the clock by setting a time to 2.minutes.ago, >> for example. > > I've had the experience, as have others I imagine, of putting a > future date in a fixture and then, six months later, wondering why my > test wasn't passing... so I'm all for "ago" and friends :-) > >> (And "hardware" covers "profile". We don't care if B takes a trillion >> clock cycles, on a magic CPU that can run them all instantly.) >> >> However, some teams go mock-crazy (even those subjected to high-end >> consultants), and mock everything for no reason. Don't do that! > > It's all about doing it for a reason; I'm just adding to the list. > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > * Advancing With Rails August 18-21 Edison, NJ > * Co-taught by D.A. Black and Erik Kastner > See http://www.rubypal.com for details and updates! > > -- Me, I imagine places that I have never seen / The colored lights in fountains, blue and green / And I imagine places that I will never go / Behind these clouds that hang here dark and low But it's there when I'm holding you / There when I'm sleeping too / There when there's nothing left of me / Hanging out behind the burned-out factories / Out of reach but leading me / Into the beautiful sea