# Functional, integration and uni tests: when, what?

**URL:** <https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120>\
**Category:** Rails\
**Created:** [December 21, 2006, 4:10pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120 "2006-12-21T16:10:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 4:10pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/1 "2006-12-21T16:10:25Z")

</div>

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? 🙂  
thanks

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/2 "2006-12-21T16:48:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 4:56pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/3 "2006-12-21T16:56:06Z")

</div>

removed\_email\_address@domain.invalid 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 ☹ ) 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 ?

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/4 "2006-12-21T17:12:43Z")

</div>

Hi –

On Thu, 21 Dec 2006, removed\_email\_address@domain.invalid 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](http://www.manning.com/black))  
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](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/5 "2006-12-21T19:33:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/6 "2006-12-21T19:47:14Z")

</div>

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? 🙂  
> 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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 21, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/functional-integration-and-uni-tests-when-what/80120/7 "2006-12-21T19:45:11Z")

</div>

On Dec 21, 8:10 am, john [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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? 🙂  
> 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
