I’m not really that good at testing. So what, so are a lot of people. Having some tests is better than none! And, the way testing tutorials are written can seem really complex and scary. Today I started thinking about the simplest possible way to get started with web app testing.
When I’m getting back into a project after not working on it for a while, I just want to know whether the application works. I want to know whether it will run on my development environment, even if I’m on a new machine. I have three computers that I use at various locations so this is important to me.
So for me the simplest possible test would be:
- The home page should load. That is the default route should return a successful page without any errors. It will have some key piece of text that says it’s working.
Here’s how I do it with cucumber:
If you haven’t installed the cucumber gems yet, put this in your config/test.rbfile.
If you haven’t cucumber set up yet, run
script/generate cucumber
Then, create the file below:
File: features/homepage.feature
Feature: View homepage for app In order to make sure the app loads As a user I want to see the home page Scenario: Homepage should say Search When I go to the homepage Then I should see "Search"
Tip: none of what you write in the Feature section really matters. It’s just for you or your client’s benefit.
Then, run
cucumber features
You should get the following output:
:> cucumber features
Feature: View homepage for app
In order to make sure the app loads
As a user
I want to see the home page
Scenario: Homepage should say Search # features/homepage.feature:6
When I go to the homepage # features/step_definitions/webrat_steps.rb:10
Then I should see "My Telltale Text" # features/step_definitions/webrat_steps.rb:118
1 scenario (1 passed)
2 steps (2 passed)
Some cool things about this: “the homepage” is something that cucumber / webrat understands out of the box. See features/step_definitions/webrat_steps.rb for how to define other custom route names. And also, “I should see “something in quotes” is out of the box cucumber goodness.


