Recently I’ve been spending some time with Cucumber and joined the cucumber gitter channel when somebody pointed out that they were having trouble running Cucumber from the command line. I usually run Cucumber from Maven, so I thought it would be interesting to see what was required to run cucumber from the command-line.
As described in the documentation you can run Cucumber features from the command-line by using the cli-runner with the following command:
|
|
You can get help by using the --help
option:
|
|
This looks pretty straightforward if you are familiar with Java, but the ‘hard’ part comes from understanding how to use the java command with its classpath options.
One important aspect is that the cucumber.api.cli.Main
class is located in the cucumber-core jar file, so when you want to run this class you need to provide the cucumber-core jar on your classpath. In this case, I take the jar(s) from my maven repository and include all required dependencies:
|
|
If you run this it should result in the following message:
|
|
Now to be able to run we need to run a feature file you will need to provide two additional arguments:
- Your feature file(s)
- Your glue code (step definitions, hooks, etc)
Your feature files can be added to the end of the command line:
|
|
This will probably result in the following message:
|
|
This means it can’t find the step definitions, hooks, etc that correspond to your feature file.
Let’s add the glue code required for running the tests. In the below example I’ll use my maven projects target directory, which contains my step definitions in the test-classes directory. You can do that by adding the directory to your classpath and with --glue com.sitture.definitions
provide the package the step definition class files are in.
|
|
This should result in something similar to:
|
|
Which seems about right and shows how we can run cucumber from the command line with the Cucumber CLI.