Scalatest Playframework必须包含List [String]

时间:2016-04-18 19:03:51

标签: scala playframework scalatest

我正在使用playframework 2.4.x和这个库

"org.scalatest" %% "scalatest" % "2.2.1" % "test"
"org.scalatestplus" %% "play" % "1.4.0-M3" % "test"

我想检查一下我在测试中构建的List中是否有一些字符串,这是代码

val userTeams = validateAndGet((teamsUserResponse.json \ "teams").asOpt[List[TeamUser]]).map( x => x.teamKey )
userTeams must contain ("team1", "team2")

但我收到此错误

List("team1", "team2") did not contain element (team1,team2)

1 个答案:

答案 0 :(得分:3)

如果您编写("team1", "team2"),那么您实际上是创建一个由两个字符串组成的元组,这些字符串来自ScalaTest匹配器的单个元素。

Based on documentation您必须使用allOf

userTeams must contain allOf ("team1", "team2")