我的特性文件场景是这样的:
When Recipe4 is added to the recipe book
对应的StepDef是:
@When("^(.*) is added to the recipe book$")
public void addRecipeTest(Recipe recipe) throws RecipeException {
//Set up
recipe = new Recipe();
recipe.setName("Hot Chocolate");
recipe.setAmtChocolate("4");
recipe.setAmtCoffee("0");
recipe.setAmtMilk("1");
recipe.setAmtSugar("1");
recipe.setPrice("65");
assertEquals(true,coffeeMaker.addRecipe(recipe));
assertEquals(coffeeMakerMain.getMode(),Mode.WAITING);
System.out.println("Recipe is added");
}
我想看看我是否能让我的代码接受正则表达式作为一个(Recipe)类对象,但我得到这个错误:
cucumber.runtime.CucumberException: Don't know how to convert "Recipe4" into edu.ncsu.csc326.coffeemaker.Recipe.
谁能告诉我我做错了什么?这是我如何将字符串转换为pojo
When I add user by passing <userInfo> to pojo class from scenario outline
Examples:
|userInfo|
|TestFirstName,TestLastName|
转换器是这个
@ParameterType(".*?")
public addUserPojo defineStringToPojo(String adduser) {
List<String> usr = Arrays.asList(adduser.split(","));
return new addUserPojo(usr.get(0),usr.get(1));
}
步骤定义
@When("I add user by passing {defineStringToPojo} to pojo class from scenario outline")
public void AddUserWithPOJOScOut( addUserPojo adduser) throws MalformedURLException, InterruptedException {
System.out.println("firstname..."+adduser.getFirstName());
System.out.println("LastName..."+adduser.getLastName());
}
pojo是这个
public class addUserPojo {
private String FirstName;
private String LastName;
public addUserPojo(String fname, String lname){
this.FirstName = fname;
this.LastName=lname;
}
public String getFirstName() {
return FirstName;
}
public String getLastName() {
return LastName;
}
}
因为你没有使用场景大纲,你不必做split
,只使用字符串,它应该工作