Joshua Java

Do we need to unit test Rails apps?

Posted on: February 28, 2009

Currently I am making a website using Ruby on Rails for my beloved. Moving in from Java I found developing Rails apps is very convenient as I can see changes directly (with few exceptions though) without restarting the server. With that in mind, I was wondering whether we still need to unit test Rails apps. Luke Francl explained in his presentation and interview why testing is overrated. I must agree that it is quite true that unit testing seems to be overrated for Rails apps because unit testing grew up from static language like Java and because you want to make sure your code works before you test it on a real server. So back to the question, what’s the point of doing TDD and BDD in Rails apps? If I’m developing with Rails, what is the advantage of unit testing over usability testing by human? Is there still anything useful from doing TDD in Rails?

About these ads

7 Responses to "Do we need to unit test Rails apps?"

It’s one thing to say that testing is overrated. It’s another to say you should abandon it altogether. While nothing will replace good old human testing. Proper tests for your Rails app with certainly help you find many bugs more quickly than you would otherwise. Imagine if every time you made a little change you had to retest your whole app by hand. That sure doesn’t sound fun to me. With automated tests and autotest (or some similar tool) you can give your app a general testing every time you do make a little change, and save the intensive manual testing for significant releases.

I think the unit test is useless, cause there is nothing compare to human testing of the application

TDD & BDD keep my code clean & simple because i just write code that make test passes.

gives me confidence

In my opinion, yes, we need to write tests (units, functionals, and integration), because Ruby doesn’t have compiler to check errors in our code, like Java does.

Sorry iaku, but having a static langauge and a compiler doesn’t check for more than basic errors. Otherwise you’d never unexpectedly encounter NullPointerException in your Java application at runtime, now would you?

Static languages and compilers do some basic error checking, mainly for syntactical correctness and basic type handling. The latter isn’t so do-able in dynamic languages as types aren’t predeclared, known and frozen at design time, in a way a compiler can detect. Testing may _seem_ more important in dynamic languages because you don’t have static type checking, but I find that’s a false assertion. Testing has equal weight in my experience, be it Java, C# or C++, or Ruby, Python, Javascript or other.

I agree, the edit, save, reload cycle that you get for RAILs will only demonstrate the page you are editing works. That unfortunately says nothing about the forgotten affects your code change has on other pages, be it a changed link, an API change, or some state representation change that you didn’t account for in every last page.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: