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 <dblack@xxxxxxxxxxx> 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

.



Relevant Pages

  • History of German Law Reference
    ... "A History of Germanic Private Law" by Rudolf Huebner is ... The book provides an authoritative discussion of the history of German ... additional understanding of genealogical topics. ...
    (soc.genealogy.german)
  • Re: Hi experts, I cant understand what proper time and coordinate time are, can you help?, thanks
    ... Then I try to imagine a bunch of events ocurring at the same place ... as the clock, but I only can see the clock. ... It is clear that if the observer observed them at the same time, ... Proper time and coordinate time are concepts invented by relativists ...
    (sci.physics.relativity)
  • Re: Hi experts, I cant understand what proper time and coordinate time are, can you help?, thanks
    ... "In relativity, proper time is time measured by a single clock ... Then I try to imagine a bunch of events ocurring at the same place as ... coordinate time can be applied to events that occur ...
    (sci.physics.relativity)
  • Re: unit testing advice
    ... hardware - networks, robots, tape drives, the clock, etc ... You can also avoid mocking the clock by setting a time to 2.minutes.ago, ... It's all about doing it for a reason; I'm just adding to the list. ... Rails training from David A. Black and Ruby Power and Light: ...
    (comp.lang.ruby)
  • Re: micro power square wave oscillator
    ... First, low voltage. ... clock between its end points. ... I kind of imagine that the usual crystal model most of us are likely ... very low power using discrete parts I just learn to appreciate how ...
    (sci.electronics.design)