Functional, integration and uni tests: when, what?

hi, I’ve just a doubt about this tests. When (/for what) use for example
functional tests instead of integration tests o r unit tests?
Can someone explain me this? :slight_smile:
thanks

unit tests test the model/database part of the operation
functional tests test a single controller
integration tests test any and all controllers simulating a session by
one or more users.

I believe that anything done by a functional test could be done by an
integration test - I guess that functional tests are slighly simpler
and thus better if that is all that is required.

I look forward to being corrected by someone better informed

[email protected] wrote:

unit tests test the model/database part of the operation
functional tests test a single controller
integration tests test any and all controllers simulating a session by
one or more users.

I believe that anything done by a functional test could be done by an
integration test - I guess that functional tests are slighly simpler
and thus better if that is all that is required.

I look forward to being corrected by someone better informed

ok…in a blog(or site, i don’t remember :frowning: ) I’ve read that they use
functional tests to test things like layouts, redirections, etc and with
integration tests the functionality for each story with/without other
stories…what do you think?
if you do, for example, some tests about the login as functional tests,
with integrations test do you test another time the login ?

Hi –

On Thu, 21 Dec 2006, [email protected] wrote:

unit tests test the model/database part of the operation
functional tests test a single controller
integration tests test any and all controllers simulating a session by
one or more users.

I believe that anything done by a functional test could be done by an
integration test - I guess that functional tests are slighly simpler
and thus better if that is all that is required.

At RailsConf Europe, the question came up on the core team panel
whether functional tests were in effect obsolete because of
integration tests. There was some interesting discussion, and a
couple of different perspectives.

I have to admit I write relatively few functional tests. I’m not
claiming that’s a best practice; I just find myself reaching for
integration tests, since they are a superset of functional tests and I
have no particular reason to favor the “test one controller at a time”
principle as long as I feel I’ve tested what I need to.

Maybe it’s just that I hit a few cases where I had to jump through
hoops to run two controllers in a functional test (e.g., to perform a
login and then do something else), so I tended to view integration
tests as a superior way to do what I was already doing and more.

David


Q. What’s a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

The problem with the Rails 1.2 RC1 is that there are bugs in the API
that
makes the integration testing very difficult. I have found that unit
testing
and functional testing helps me to keep moving forward with my project
when
I am adding features as well as when I am refactoring.

Instead of doing integration testing, for the time being I have decided
to
use Selenium on Rails as a substitute. When the bugs are fixed I will be
doing more integration tests.

john wrote:

hi, I’ve just a doubt about this tests. When (/for what) use for example
functional tests instead of integration tests o r unit tests?
Can someone explain me this? :slight_smile:
thanks

I think it’s down to a matter of taste to a fair degree (as the
discussion at the London RailsConf demonstrated with core members taking
different views. I prefer to use functional tests for well defined,
encapsulated actions (and they seem to work nicely with REST perhaps for
this reason).

On the other hand integration tests seem to work better either with a
story based approach, or where you are testing a more complicated
scenario.

Unit tests, however, are my favourite – particularly now that I’ve
embraced the skinny controller fat model approach – as I like as much
of the action to be handled at model level.

Just my $0.02

On Dec 21, 8:10 am, john [email protected] wrote:

hi, I’ve just a doubt about this tests. When (/for what) use for example
functional tests instead of integration tests o r unit tests?
Can someone explain me this? :slight_smile:
thanks

If you’ve never used tests before I would recommend starting with unit
tests. They are a little easier to get your head around and form the
basis for functional and integration tests. Without good unit tests
you’ll end up chasing down model bugs in your functional and
integration tests.

Aaron