Ram wrote:

> Well I have this fairly large application with restful authentication
> and a few other plugins in it. I developed it wholly otherwise.
> This is my first ROR app. And I learnt of Test Driven Development
> quite late.
> Ive reached the point where I need to cover my code with good test
> coverage.

Open a new Rails project in a new folder.

Rewrite every tiny detail of your old project into the new one.

If your old project has a model Foo, you start with script/generate model Foo, 
and get the foo_test.rb. You edit that to write a _useful_ test on one or two 
fields of Foo, and you pass the test by adding those fields to the migration 
and 
doing something with them in a method inside Foo.

(BTW, don't add a migration for each field - edit the existing migrations until 
you deploy them...)

Going this way prevents you from cheating, and helps you refactor. The new 
project should be finished very soon.

> - should i start with unit tests? how paranoid should i be about them
> (if at all there's a unit of measurement for that)?

The test to code ratio should be 2:1. And start with useful features, not 
layers. To write a useful feature, write new tests and code into each layer 
that 
it needs.

> - i understand too much dependency on fixtures can make my tests
> brittle. So i keep fixtures to a minimum? when exactly should I
> absolutely use a fixture?

Using my schedule, your fixtures will not be brittle. Just don't write 
assertions that expect useless things, like a count of found records. Test that 
all the records matched the find criteria.

> - what tools should i definitely use besides test/unit? RSpec,
> Autotest, Cucumber, Selenium, ... ?

Those are mostly for documenting features to customers, not for TDD. Stick with 
unit tests, because RSpec would only add clutter if used as a TDD tool.

Autotest is because all the Rails editors truly suck, and do not let you run 
one 
test at a time. (Yes, textmate lets you run one test at a time - if you rotate 
the freaking document back to the correct test between every edit. The quality 
of these editors makes me wonder if anyone who develops them actually uses TDD.)

> What would probably be most important is how do I analyze my code to
> see what tests are most important and start writing them? How do I
> approach writing tests?

Add features to your new project in order from highest business value and on 
down.

-- 
   Phlip


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to