Search code examples
javajunitcucumberbddcucumber-java

Simple Cucumber Test Class Passes with no Glue File


This has been puzzling me for half a day now. I can't seem to find the issue. Basically I have my Test runner, feature file, and the steps file in my workspace. The java files are in the same package (i.e. no package).

Below is my TestRunner.java

import org.junit.Test;
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "test/resources/features", tags = { "~@Ignore" })
public class TestRunner {

    @Test
    public void feature() {
    }
}

My feature file, helloWorld.feature

Feature: Simple Test Feature

Scenario: Run Scenario ONE
GIVEN step one
WHEN step two
THEN step three

and my steps file CucumberJava.java,

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class CucumberJava {

    @Given("^step one$")
    public void step_one() {

        System.out.println("step one");
    }

    @When("step two")
    public void step_two() {
        System.out.println("step two");
    }

    @Then("^step three$")
    public void step_three() {
        System.out.println("step three");
    }
}

When I execute TestRunner.java as JUnit, everything passes, but I get the following in the console:

0 Scenarios
0 Steps
0m0.000s

WHY? In fact, when I remove CucumberJava.java from the project, I get the exact same output. What am I missing? I also tried setting the glue option in TestRunner.java code too; still the same result.

Your help is highly appreciated.


Solution

  • The feature file words like Given etc are in uppercase in your feature file. They need to be like Given ie sentence case.

    Feature: Simple Test Feature
    
    Scenario: Run Scenario ONE
    Given step one
    When step two
    Then step three
    

    Also you might need to append a 'src' to the feature path in the runner. Like this features = "src/test/resources/features", if you are using Maven. Also no need to have a @Test annotation and method inside the runner.