您使用的是 2.7.7 吗?在 2.8 中,具有相同元素(以相同顺序)的不同 Seq 应该相等:
scala> import org.scalatest.matchers.ShouldMatchers._
import org.scalatest.matchers.ShouldMatchers._
scala> import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArrayBuffer
scala> val list = List(1, 2, 3)
list: List[Int] = List(1, 2, 3)
scala> val arrayBuffer = ArrayBuffer(1, 2, 3)
arrayBuffer: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3)
scala> list == arrayBuffer
res2: Boolean = true
scala> arrayBuffer == list
res3: Boolean = true
scala> list should equal (arrayBuffer)
scala> arrayBuffer should equal (list)
2.8 中这个规则的一个例外是数组,它只能等于其他数组,因为它们是 Java 数组。(当您对它们调用 .equals 时,Java 数组不会在结构上进行比较,但 ScalaTest 匹配器确实会在两个数组上进行结构相等。)