Search code examples
javacucumberintellij-plugin

Add an Exception to Cucumber Java Step Definition Template


I´m using intellij with the cucumber plugin. If I use the code template to create a Step Definition I get

@Given("User does sth")
public void userDoesSth(){
}

What I want to have is

@Given("User does sth")
public void userDoesSth(){
  throw new io.cucumber.java.PendingException();
}

If I try to change the template in intelliJ

@${STEP_KEYWORD}(${STEP_REGEXP})
public void ${METHOD_NAME}${PARAMETERS} {
  ${BODY}
}

by adding a "throw new PendingException()" I get

@Given("User does sth")
public void userDoesSth(){
  throw new cucumber.api.PendingException();
    }

Is there any way to change this?

Thx, Nicca


Solution

  • IntelliJ's gherkin plugin replace PendingException word with cucumber.api.PendingException.

    Even if you use a full-qualified name like throw new io.cucumber.java.PendingException(); plugin appends cucumber.api.

    It may worth to report this issue to Gherkin Plugin developers. You may check if there is a fix after any gherkin plugin updates.

    In the meanwhile, if it is a necessary to have step generation from IDE, you may use temporarily this snippet.

    @${STEP_KEYWORD}(${STEP_REGEXP})
    public void ${METHOD_NAME}${PARAMETERS} {
      throw new RuntimeException("TODO: implement me");
    }
    

    This will imitate PendingException's behaviour.