简体   繁体   中英

can't run TestNG or JUnit test

I worked in project which I implemented a simple feature, stepdefinition class and the runner and want to test it using testJUnit or when I run TestNG.xml.

but I have this problem

You can implement missing steps with the snippets below:

@Given("^sample feature file is ready$")
public void sample_feature_file_is_ready() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I run the feature file$")
public void i_run_the_feature_file() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^run should be successful$")
public void run_should_be_successful() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

my feature is :

@smokeTest
Feature: To test my cucumber test is running
I want to run a sample feature file.

Scenario: cucumber setup

Given sample feature file is ready
When I run the feature file
Then run should be successful

My stepdefinition is :

public class Test_Steps {

      @Given("^sample feature file is ready$")
      public void givenStatment(){
            System.out.println("Given statement executed successfully");
      }

      @When("^I run the feature file$")
      public void whenStatement(){
         System.out.println("When statement execueted successfully");
      }

     @Then("^run should be successful$")
      public void thenStatment(){
         System.out.println("Then statement executed successfully");
      }

My runner is :

@RunWith(Cucumber.class)
@CucumberOptions(
     features = {"D:\\feat\\user"},
     glue={"stepsdef"},
     tags= "@smokeTest")
public class RunnerTestInChrome extends AbstractTestNGCucumberTests {

}

How can I know that the stepdefinition class is related to my features! I don't understand the problem I implemented the methods scripts

This means that Cucumber cannot find your glue code (step definitions).

For the glue instead of glue={"stepsdef"}, provide the path to stepsdef .

Btw, it's recommended to have your feature files in src/test/resources :)

If you can't get it to work, please try the cucumber-java-skeleton ; it's designed to work "out of the box" and should be easier to use than setting up your own project.

If you do want to set up your own project, have a look at this blogpost , which should guide you through the steps of setting up your project and having your files in the right directories...

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