Forum: Ruby on Rails Rails Testing : Not Just For The Paranoid article

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2007-06-07 23:03
(Received via mailing list)
Though I'm primarily working on plain old Ruby with a handful of
Camping here and there, I've been writing a couple articles about
Rails that might be interesting to the novice-to-intermediate crowd.

My article "Rails Testing : Not Just For The Paranoid" just came out
today, and in it I show unit, functional, and integration testing by
example.  It was tough to work in 'really cool' examples and keep with
a word limit, but I think it might still be helpful.

http://www.oreillynet.com/pub/a/ruby/2007/06/07/ra......

I'd be happy to hear feedback from beginners about whether anything
confused you in the article, so I can use those pointers for future
articles.

>From the advanced folks, I'd like to know if I'm doing anything that

reeks of bad style.  I'm mostly a Rails observer, so that's entirely
possible.

Otherwise, I hope you find the article useful.

-greg
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2007-06-07 23:05
(Received via mailing list)
On Jun 7, 5:03 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:

> My article "Rails Testing : Not Just For The Paranoid" just came out
> today, and in it I show unit, functional, and integration testing by
> example.  It was tough to work in 'really cool' examples and keep with
> a word limit, but I think it might still be helpful.
>
> http://www.oreillynet.com/pub/a/ruby/2007/06/07/ra......

Whoops!

http://www.oreillynet.com/pub/a/ruby/2007/06/07/ra...

also a tinyurl:

http://tinyurl.com/24a33s
18989f5699fa8619c8e9b301b6cb5088?d=identicon&s=25 BraveDave (Guest)
on 2007-06-08 19:47
(Received via mailing list)
Gregory,
Thank you for the article you posted on testing. I went through this
and your examples this morning and feel you could help people more if
you taught them the 'rational' that would help one find the right
coding/results equation for testing. Your basic point is that one
"should test everything". I find this hard to swallow in a practical
world with only 24 hour days.

I suggest those interested should look at this article as it seems to
tie together more practical examples:
http://manuals.rubyonrails.com/read/chapter/20
David
8608f2d7f02c6d0f1c349b7b94b1cea5?d=identicon&s=25 liquidautumn (Guest)
on 2007-06-08 20:18
(Received via mailing list)
Most noticeable issue is that you are not mocking out model methods in
functional tests and never mentioned mocks/stubs at all.
By the way, have you tried rspec? Once tried I'm addicted, despite of
lots of black magic, making it hard to trace down problems, if those
occured, it's really really good.
Also, like most of tech writers does, you're writing on testing from
technical standpoint, while some information on theoretical aspects
would make your article much more valuable.
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-06-08 20:20
(Received via mailing list)
So what's the point of testing if you're not going to have 100% code
coverage through your tests? How are you going to prove your application
works? If one part of the application is not tested, then you can not
trust
the rest of your application.

Those who say "there's not enough time to test," from my experience,
haven't
even given it a try, or want to but are still in the "code first, test
afterwards" mentality.

You NEED to write your tests first, THEN your code. It's the only way
you
can be sure that all of your code is properly tested. And as for time,
it's
a very simple change to project management. The typical, non-TDD project
timeline goes like this:

|--- initial design --- | ---- Coding ---- | --------------- testing
------------------ |

With TDD, you basically merge coding and testing, and end up with this
project timeline pattern:

|--- initial design --- | ---- TDD ------------------ | -- testing -- |

So yeah, the coding takes a little longer, but the final end-to-end
testing
is a VASTLY shorter time period, because you can prove the inner
workings of
your application, and if you write integration tests as well, you can
prove
interactivity is correct as well. In the end, projects are done faster,
more
bug-free, and with a better design and cleaner code.

Jason
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2007-06-08 20:56
(Received via mailing list)
On Jun 8, 2:18 pm, liquidautumn <d...@talentboom.com> wrote:
> Most noticeable issue is that you are not mocking out model methods in
> functional tests and never mentioned mocks/stubs at all.

Yup, it was in my original outline but got cut due to article length
constraints

> By the way, have you tried rspec? Once tried I'm addicted, despite of
> lots of black magic, making it hard to trace down problems, if those
> occured, it's really really good.

Actually, I'm going to be doing a 3 part series on BDD for O'Reilly
towards the end of the summer. :)  I've not been using it much in
practice, but we just swapped ruport-util's tests to specs and will be
using it more in work, too.  It seems worth investigating for sure.

> Also, like most of tech writers does, you're writing on testing from
> technical standpoint, while some information on theoretical aspects
> would make your article much more valuable.

Yes, that's probably true.  I think that I might expand the article
down the line, but I did consciously avoid theory in it, so I'm not
surprised you mentioned that.  Next time around, I'll try to at least
cite a few sources for those who want more background.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2007-06-08 21:01
(Received via mailing list)
On Jun 8, 1:46 pm, BraveDave <DauntlessDa...@gmail.com> wrote:
> Gregory,
> Thank you for the article you posted on testing. I went through this
> and your examples this morning and feel you could help people more if
> you taught them the 'rational' that would help one find the right
> coding/results equation for testing. Your basic point is that one
> "should test everything". I find this hard to swallow in a practical
> world with only 24 hour days.

If you walk into an application mid way, maybe it'll be tough to
immediately layer code in, that's true.  Also, when I first started
doing camping, I didn't really have the time to mess around learning
mosquito (it's test framework) in time for my first gig with it.
However, once you get into TDD/BDD, it becomes entirely possible to
write tests for everything, especially if you write them first.

If you treat them as part of the design process, you spend zero time
writing down things on paper and all the time writing the code.  It's
true, you need to have a lot of experience to make Test-First and Test-
Everything make sense for your development process.  Still, it's one
of the best skills I've picked up, and while I'll be honest and say I
slip from time to time, usually my code with tests is surprisingly
written faster and has less issues than the code where I've left red
zones or not tested at all.

I'm not talking about slim margins, either.  I'm estimating from my
past work, that the increase in productivity is anywhere from 50% to
200% better on any given job.

In terms of Ruport, our almost complete coverage for the core library
has been a tremendous safety net.  Not everything was written test-
first, but the stuff that is came out better.  That's just my
experience.  You might try it for a small project that you can take
the time to learn on, and see how it works for you.

-greg
This topic is locked and can not be replied to.