# Advice on testing

**URL:** <https://www.ruby-forum.com/t/advice-on-testing/134410>\
**Category:** Rails\
**Created:** [April 10, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/advice-on-testing/134410 "2008-04-10T16:17:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [April 10, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/advice-on-testing/134410/1 "2008-04-10T16:17:51Z")

</div>

I’ve been programming for a long time, but never really done any serious  
application testing. There’s a mass of information on the web about  
testing: TDD vs. BDD, fixtures vs. factories/mocking etc.

From my research I have a few questions that I cannot find the answers  
to:

- What mocking frameworks are people using (are Mocha or FlexMock  
production ready?)
- What is the ‘test/mocks’ directory for in a default Rails application  
– don’t you normally define your mocks in your test case?
- Should I be unit testing models _and_ controllers? Or just unit  
testing models and then functional testing controllers.
- What exactly does _functional testing_ mean?
- Do I need to use fixtures at all in my unit tests?
- Should I be using fixtures in my functional tests?

After reading about, and trying several testing setups I have decided to  
use plain old Test::Unit with the Shoulda plugin  
([thoughtbot case studies featuring design and development projects for websites, mobile and web applications.](http://thoughtbot.com/projects/shoulda)). I am having is finding a  
really good example of a Rails app with this kind of testing setup. Any  
recommendations?

Any help much appreciated!

~ Mark

---

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [April 10, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/advice-on-testing/134410/2 "2008-04-10T16:36:10Z")

</div>

> - What mocking frameworks are people using (are Mocha or FlexMock  
> production ready?)

we use rspec, works fine for us

> **[RSpec: Behaviour Driven Development for Ruby](http://rspec.info/)**

> - What is the ‘test/mocks’ directory for in a default Rails application  
> – don’t you normally define your mocks in your test case?

with rspec we do, so i can’t tell you 🙂

> - Should I be unit testing models _and_ controllers? Or just unit  
> testing models and then functional testing controllers.

in the rails tests unit test == model  
functional test == controller  
rspec simply names the thing model & controller

> - What exactly does _functional testing_ mean?

testing the functionality of your app, i guess

> - Do I need to use fixtures at all in my unit tests?
> - Should I be using fixtures in my functional tests?

hmm, could be difficult to test a db app without data in the database  
we normally make extensive use of fixtures, have one record for each  
table minimum and of course additional for each “special case” that  
needs testing  
(show all invoices, show paid invoices, show unpaid…)  
if you define associations you’ll want to test them and so on…  
if you use pagination, you’ll want at least page\_size + 1 records  
and while developing your app and viewing the stuff in the browser  
you’ll find fixture data very helpfull, having some basic setup with a  
default user, admin products, payments. i can’t see how you could do  
without them

---

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [April 10, 2008, 6:00pm UTC](https://www.ruby-forum.com/t/advice-on-testing/134410/3 "2008-04-10T18:00:08Z")

</div>

On 10 Apr 2008, at 15:17, Mark D. wrote:

> production ready?)  
> I’m very happy with mocha.

> - What is the ‘test/mocks’ directory for in a default Rails  
> application  
> The things in there are loaded for the respective environments. So to  
> give a concrete example, in our app we send sms to customers via a  
> gateway, that functionality goes through a class (lets call it  
> SMSProxy). The real implementation of SMSProxy posts the data to the  
> relevant place, but obviously we don’t want that to happen in  
> development or testing, so we have a mock in there that just records  
> the fact it was called with whatever parameters.

> – don’t you normally define your mocks in your test case?
> 
> - Should I be unit testing models _and_ controllers? Or just unit  
> testing models and then functional testing controllers.
> - What exactly does _functional testing_ mean?
> - Do I need to use fixtures at all in my unit tests?
> - Should I be using fixtures in my functional tests?

There’s a school of thought that in functional testing you should just  
be mocking out all the model stuff and just check that the right  
things are being called with the right parameters and so on. This does  
avoid some duplication in your tests and will make them run faster and  
so on. On the other hand, if your test asserts the Foo.do\_bar is  
called with arguments x,y,z but the implementation of Foo.do\_bar  
changes so that it now requires different parameters you’d have to  
remember to change the expectation that you set.

Fred
