如何将Cucumber数据表映射到Scala?

如何将Cucumber数据表映射到Scala?,scala,cucumber,cucumber-jvm,Scala,Cucumber,Cucumber Jvm,代码: 我的意思是asMaps方法返回一个列表[Map[String,String]]类型,我想将它保存到SomeVariableIwantSave val,这样我就可以在其他步骤中使用它,但我不确定初始化它到什么,以及如何在没有大量代码干扰的情况下正确地映射它。你不能“将某些内容保存到val”,因为vals无法更改。因为您只在这一步中获取请求数据,而不在其他步骤中获取请求数据,所以您应该 val someVariableIWantToSave //I do not know what t

代码:

我的意思是asMaps方法返回一个列表[Map[String,String]]类型,我想将它保存到SomeVariableIwantSave val,这样我就可以在其他步骤中使用它,但我不确定初始化它到什么,以及如何在没有大量代码干扰的情况下正确地映射它。

你不能“将某些内容保存到
val
”,因为
val
s无法更改。因为您只在这一步中获取请求数据,而不在其他步骤中获取请求数据,所以您应该

val someVariableIWantToSave    //I do not know what to do here

When("""^this request is sent to the XYZ service:$"""){ (requestData:DataTable) =>
 //// we might want to do somethign else with Datatable in the mapping of the       feature, nothing yet
var someVariableIWantToSave = requestData.asMaps()

}

这就是我的解决方案。因为这只是使用var的测试代码,所以在这里是可以的。。我在测试中将其设置为全局,然后其他步骤可以使用它

When("""^this request is sent to the XYZ service:$"""){ (requestData:DataTable) =>
  val someVariableIWantToSave = requestData.asMaps()
  // do something with someVariableIWantToSave
}

`

我想在其他步骤中使用该请求数据
var request: java.util.List[java.util.Map[String, String]] = _

When("""^this request is sent to the blah service:$"""){ (requestData:DataTable) =>
request = requestData.asMaps() 
}