我有一个类似以下的收藏
val buffer: Buffer[Try[E]]
,我想断言buffer
中不包含任何Failure
。理想情况下,我想这样做
buffer should not contain a[Failure[_]]
但是,似乎不能正确检查类型。
答案 0 :(得分:0)
您能指定您的问题吗?
以下代码编译并运行
src / test / scala / Test1.scala
import org.scalatest.FlatSpec
import org.scalatest.Matchers._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try}
class Test1 extends FlatSpec {
class E
val buffer: mutable.Buffer[Try[E]] = ListBuffer(Success(new E), Success(new E))
buffer should not contain a[Failure[_]]
}
a
/ an
应该与
an [IndexOutOfBoundsException] should be thrownBy s.charAt(-1)
http://www.scalatest.org/user_guide/using_matchers
尝试
buffer filter(_.isFailure) should be (empty).