← Back to Upcase

How to run a cucumber test?


(Kim Khan) #1

I need to run a cucumber test for the first time. What tutorials/articles should I read that will get me up to speed on the basics quickly?


(Joel Quenneville) #2

To run a cucumber feature just run the following on the command line

cucumber path/to/feature

If you are looking for an intro to writing cucumber specs you might want to check this blog post


(Kim Khan) #3

Thanks those instructions. In the environment that I am working in we have several apps that are combined to run our service. So I changed the dir to the app where I thought the test should be run.
cd apple\feature
ls
cucumber how_to_peel_an_apple

So cucumber how_to_peel_an_apple worked.
cucumber how_to_peel_an_apple -n didn’t work. Do you know why?

Also, since I need to run a test that will test our service from beginning to end which will span several apps how do I get a list of all the cucumber tests?

When I try to find in Sublime using
cmd t
.feature

I only get a few tests. Why is that. I added the root of the Project folder so it should be able to search thru all the apps.


Also, I need help on getting past the errors the cucumber test displays.

Thanks in advance for any help.


(Joel Quenneville) #4

Running multiple features

Instead of just pointing cucumber to a single feature file, you could point it to a directory and cucumber will run all the features within that directory. Cucumber features are usually located under a features/ directory in the root of each project. To run all the features for an app you could use the following:

cucumber features/

cucumber -n

Cucumber’s -n option works as follows:

-n, --name NAME

Only execute the feature elements which match part of the given name. If this option is given more than once, it will match against all the given names.

So

cucumber how_to_peel_an_apple.feature -n 'Using a knife'

would only run the scenario named ‘Using a knife’ within the how_to_peel_an_apple.feature file. You can get more info on the cucumber wiki.

Getting a list of all cucumber features

As mentioned above, the features should all be in a features/ directory in the root of each app. If Sublime is not picking up all of the files, could it be that some of these features do not have the .feature extension? It is also possible that you haven’t set up the Sublime project correctly.

Alternatively, you could run the following on the command-line from the root of your project.

ls **/*.feature

This will list all files files ending in .feature in the current directory or any of its descendents

Fixing red tests

When you get a test failure, it will print out a message trying to explain what went wrong and where. It will tell you in what file and at what line number the error occured. This is the first place to check when trying to figure out what went wrong.


(Kim Khan) #5

Ok! This worked when I ran cucumber from the root dir of the app. When I ran from the features dir of the app I got the following err.

I am getting a You don’t have a ‘features’ directory. Please create one to get started. Eventhough I am running the cucumber test from the features directory.

Big Thanks!!


(Joel Quenneville) #6

The cucumber command takes a path as an argument. When you are in the root of an app and you run cucumber features/, you are telling cucumber to run all the features in the features subdirectory of your current location.

So running cucumber features/ from root of your app will look for $APP_ROOT/features/ while running cucumber features/ from within the features directory will look for $APP_ROOT/features/features/. Since the features/ directory does not have a sub-directory named features/, you get an error.

If you are already in the features/ directory, you need to point cucumber to your current location. On Unix-based systems, you can refer to the current directory with . (period). So to run from the features/ directory, you would use the following:

cucumber .

This tells cucumber to run all features in the current directory.


(Kim Khan) #7

ah ha…
Very thorough explanation. Excellent!! Thanks you again.