Topic: Testing and Selenium On Rails

Hello everyone,

I am working on a new rails application and I had a quick question. I have previously used three types of tests when developing rails applications. I use standard unit tests, the standard functional tests and then I use selenium on rails. Selenium basically allows me to easily automate actual testing within the browser. It is sort of like I am going through testing the application but instead it is all automated with selenium on rails.

I have a couple of questions. First, I see a lot of talk about rspec. Is it critical that I move to rspec for my unit and functional tests? What are the advantages and is it absolutely essential that I move to rspec because I have come to like regular unit and functional tests for my simple needs so far...

Second, is there an alternative to selenium that allows for automated testing but that works a bit better. I noticed selenium isn't updated much anymore, its a bit buggy, and I was wondering if there was a better alternative.

Basically, if I could only pick three ways to test (right now its test::unit, test::unit functional and selenium), which three would serve me and my application the best?

Re: Testing and Selenium On Rails

xgamerx wrote:

I have a couple of questions. First, I see a lot of talk about rspec. Is it critical that I move to rspec for my unit and functional tests?

I wouldn't say it's critical. There are some things I like about it and some things I don't. Here's a list.

Pros:
1. You can have multiple "describe" blocks. Think of it as multiple setup methods for different parts of the same class.
2. The syntax is better (once you get used to it)
3. It helps you write better tests by thinking of the behavior first
4. It's easy to add "pending" tests
5. It's easier to write helper methods and test the view (if you want to).
6. You can write your own matchers to make the syntax even better.
7. You can get an outline view of all your specs if you want which is kind of cool.

Cons:
1. It's not the convention, which means little odd things don't work as well (the file switching command in TextMate for example).
2. You need to use the generators they provide. They behave the same but sometimes I forget and have empty test/unit files floating around.
3. Sometimes it breaks with updates to edge rails.
4. Sometimes the syntax is more verbose then I would prefer.

There's probably more but my brain stopped working.

xgamerx wrote:

Second, is there an alternative to selenium that allows for automated testing but that works a bit better. I noticed selenium isn't updated much anymore, its a bit buggy, and I was wondering if there was a better alternative.

There's also Watr, but I haven't tried either one so I can't say which is better. Do you find these kind of tests pay off where they catch enough errors rather then false positives to make it worth the effort?

Railscasts - Free Ruby on Rails Screencasts

Re: Testing and Selenium On Rails

Thanks for your insights Ryan. Very helpful as usual. I think I will stick with the standard unit testing framework baked in because I am familiar with it but thought I would ask. As for selenium, I never know the right answer to these things but what I really like about them is that they simulate me doing the testing manually. Manually testing every facet of my program after a change is extremely difficult. I would need a checklist or something but with automated browser testing, I can rest assured that the application works in both the black box as well as white box perspectives. If this is really necessary is another question...but it gives me a (possibly false) sense of security that I have gotten used to.

Anyone else here use selenium at all? or any alternative methods for automated browser testing?