2012-11-09 51 views
0

代码:如何将Cucumber DataTable映射到Scala?

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() 

} 

我的意思是asMaps方法返回一个列表[地图[字符串,字符串]]类型,我想将它保存到someVariableIWantToSave VAL,所以我可以在其他步骤中使用它,但我不知道该如何初始化它以及如何在没有大量代码噪音的情况下正确映射它。

回答

0

因为val s不能更改,所以不能“保存某物到val”。由于您只是在此步骤中获取请求数据,而不是其他人员,因此您应该只有

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

我想使用请求数据在其他步骤 –

0

这是我的解决方案。由于这只是测试代码中使用变种是确定这里..我将其设置为全球的测试,然后其他步骤可以用它...

var request: java.util.List[java.util.Map[String, String]] = _ 

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

`