Do You Test Your Views?

Those of you following me on twitter already know that I’m learning Cucumber.

Traditionally I don’t test my views or controllers all that much. I know, I know, it’s heresy. But I’ve just never gotten much value from writing Rails functional tests nor integration tests.

Yet those of you who have been reading my articles or new book know that I’ve been immersed in TDD for a long time and can’t imagine writing any application without a decent test suite to go with it.

So what do I test? I test the models like no one’s business. I use test/unit or shoulda to drive the design of all the models I write, and I write a lot of tests covering every possible edge case I can think of.

But the controllers and views? Up until now it’s seemed like a waste of time, for several reasons.

First, most of my controllers are stupid-simple RESTful controllers. They’re as skinny as possible, because I move almost all of the real logic into the models. That way I can test my models with unit tests without trying to simulate a browser, and I find it easier to use script/console to play with models than with controllers.

Secondly, once the application gets to its first stabilization point, I find that HTML and CSS change way more often than 80% of the core application logic ever will. Writing tests for the views just means they’ll break after inconsequential layout changes. After all, views are just supposed to be a representation of your models (generally speaking), and other stuff (navigation, ajax effects, etc.) just aren’t worth my time writing a regression suite for.

As much as I’m digging Cucumber’s syntax, I’m desparately close to just going back to test/unit and forgetting about the controllers again.

Convince me otherwise. Do you test your controllers and views? If so, with what – Rails functional tests in test/unit? RSpec? Cucumber? What are you trying to verify in your tests, and why?


Is your team switching to Rails? Sign up for a fun-filled, one-day class in your own office: SwitchingToRails.com

  • Programming Language:
  • Technology: