Thursday, December 10, 2009

[Rails] Re: Things I wish I knew when beginning testing

Thanks for posting this -- it's some interesting food for thought.

> Do not mock everything to make your test/spec suite "database
> independent". Your tests are SUPPOSED to break when you change code in
> your model or controller. Mocking everything will not allow this, and
> will give you the feeling that you're developing a second application
> in your test/spec suite.
> --- Yes, it will speed up your tests/specs, but once again,
> conciseness is more important.

I think this point is debatable though. The point of mocking models
in your tests is to allow the tests to run in complete isolation.
e.g., there's no reason for your Post model tests to break when you
add a new required field to your User model. Your point is valid for
integration and other high-level tests, but unit testing is equally
important in my mind and it certainly benefits from mocking.

Jeff

On Dec 10, 1:05 am, jko170 <jko...@gmail.com> wrote:
> The following statements will save you lots of time, and most
> importantly, develop a better application when beginning Rails
> development.
>
> Fixtures are faster, but conciseness is more important. Use factories
> (Machinist or Factory girl). Don't worry about the speed of your test/
> spec suite. Use autotest or autospec.
> --- I started out with fixtures, then switched to factories. Lost
> patience and switched back to fixtures. Now back to factories for
> maintainability and conciseness.
>
> Do not mock everything to make your test/spec suite "database
> independent". Your tests are SUPPOSED to break when you change code in
> your model or controller. Mocking everything will not allow this, and
> will give you the feeling that you're developing a second application
> in your test/spec suite.
> --- Yes, it will speed up your tests/specs, but once again,
> conciseness is more important.
>
> Your test framework does not matter. Test/unit, Shoulda, RSpec all
> produce the same outcome. Choose by what syntax you feel comfortable
> with. For every great developer that uses test/unit, there is a great
> developer using RSpec.
> --- For whatever reason I cannot explain, RSpec feels most comfortable
> to me. I started with test/unit, switched to RSpec, then shoulda, then
> test/unit, and now back to RSpec. I will not switch again.
>
> Test the entire stack. Do not just test models. Test/spec models,
> controllers, and use integration tests/specs. This will give you
> confidence when developing and literally makes your work 1000 times
> less stressful. Yes, it takes more time, but it is the ONLY way to
> develop a reliable app that works.
> --- I started out just testing models. This does not catch view
> errors, and my users paid for it.
>
> If TDD or BDD does not fit your brain, don't do it. DHH doesn't do it,
> and you don't have to either. This is no excuse for not testing
> everything though.
> --- For me, TDD/BDD does not let me test/spec comfortably. I tried
> both ways, and my code always turns out better when NOT using TDD/BDD.
> I support the philosophy, but it is not "necessary". Some people will
> say I am "doing it wrong", but if the end outcome is exactly what I
> want, why does it matter how I got there?
>
> If I had known these things when beginning, I would have saved
> countless hours trying to follow the "one golden path" that does not
> exist. I hope this helps.

--

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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate