简体   繁体   中英

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

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.

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