在相同的“安排和行动”案例中有多个断言消息

时间:2019-01-29 09:48:52

标签: scala scalatest

我看过测试用例写为

"someFunction()" should "return success" in {
  // WHEN
  val response = SomeClass.someFunction(..)
  // THEN
  assert(response.status === "SUCCESS")
} 

it should "return abc in data" in {
  // WHEN
  val response = SomeClass.someFunction(..)
  // THEN
  assert(response.data === "abc")
}

我在此看到的问题是对于同一操作,我们必须编写不同的代码块。

另一种方法是在同一块中具有两个断言,例如

"someFunction()" should "WHAT message to display" in {
  // WHEN
  val response = SomeClass.someFunction(..)
  // THEN
  assert(response.status === "SUCCESS")
  assert(response.data === "abc")
}

在这里,我在同一块中有两个断言。问题是消息。 无论如何,我可以编写类似的测试

"someFunction" in {
      val response = SomeClass.someFunction(..)
}
should "return success" {assert(response.status === "SUCCESS")},
should "return abc in data" {assert(response.data === "abc")}

有没有办法让我为一组操作写带有相应消息的多个assert?

scala:2.11

0 个答案:

没有答案