Testing with Ruby On Rails
Remember those days when you fixed a bug only to introduce more bugs in return? That’s what testing is all about, to be more specific is incremental testing. When you write some procudures, you should also write the test procedures. So when a procedure is modified, you retest all the procedures available, then your codes will be less breakable.
Ruby On Rails (RoR) is built with incremental testing in mind, it supports unit testing, functional testing, mock object, performance testing, benchmarking and test data loading support. In java you will have to look at different components such as JUnit, Canoo WebTest, JMock/Easy Mock, JMeter, and DBUnit, not to mention many other libraries trying to do similar things. The problem is the learning curve is high and the components are not as cohesive as RoR test framework.
Here are some points that I like most about RoR test framework compared to Java framework:
- Test Templates
- It supports auto creation of test templates for controller and model class.
- Test Data Format:
- Thank God it’s not xml, it’s called YAML (YML Ain’t XML) or “fixtures” the term used in RoR. It’s very easy and intuitive, and hell ya, you can even include ruby codes in there, e.g.
user_supervisor: id: supervisor name: Clark Kent date_available: <%= 1.day.from_now.strftime("%Y-%m-%d %H:%M:%S") %> <% for i in 1..20 %> user_<%= i %>: id: <%= i %> name: User <%= i %> <% end %> - Unit Test
- In your test code, you can refer to the test data using @user_supervisor, which is very important to create a more flexible test code that caters to changes in test data without breaking your test procedures. e.g.
test_load_supervisor: .... assert_equal user.name, @user_supervisor.name end - Rake Command
- Rake command is Ant’s brother in Java, they do similar things, only Rake has built-in useful options for developer. I love “rake recent” to test recent updated unit tests (updated in last 10 mintues).
- Fewer Lines of Codes
- I just can’t resist repeating this point!!!


Add Your Comment