简体   繁体   中英

I've set up a simple automation framework in Eclipse using Java but cannot run Cucumber tests via Junit

I'm new to Cucumber and Java (come from a Specflow/C# background). I am trying to set up my first project in eclipse and think everything is set up correctly (my step definition file can be accessed (using F3 - go to definition) from the feature file).

I have set up a testrunner file like so:

package cucumberTest;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "Feature"
        ,tags = "@LoginTests"
        ,glue={"src/stepDefinition"}
        ,dryRun = true
        ,monochrome = true
        )

public class TestRunner {
}

My issue is that when I run Junit (v4.11) via Eclipse IDE, the tests do not run, I get told the scenarios and steps are undefined and am given suggestions to fix the issue:

2 Scenarios (2 undefined)

6 Steps (6 undefined)

0m0.105s

You can implement missing steps with the snippets below:

Given("^User is on Home Page$", () -> {

    //Write code here that turns the phrase above into concrete actions

throw new PendingException();

});

However, the syntax suggested to me is incorrect. Any ideas why the syntax is wrong and why my tests do not run?

The suggested syntax (snippets) is for java8. If you want to use regular java syntax, use cucumber-java dependency rather than cucumber-java8 dependency.

The reason you are getting the message that your steps are undefined, is because Cucumber cannot find your glue. Make sure you are providing the correct location of your step definitions in the cucumber options for "glue=".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM