Is there anyway we can give two conditions in Scalatest using ShouldMatchers

自作多情 提交于 2019-12-10 11:15:29

问题


How can I do something like this? Check for two conditions while testing

// b is Option[Array[Int]]
b should be ('empty) || b.get should be ('empty)

I want to do it using ShouldMatchers instead of assert, since ShouldMatchers is part of scalatest.


回答1:


You should be able to do

val b: Option[Array[Int]] = ???
b should (be ('empty) or be (Some(Array.empty[Int]))

See this section of the scalatest manual: Logical Expressions



来源:https://stackoverflow.com/questions/27964790/is-there-anyway-we-can-give-two-conditions-in-scalatest-using-shouldmatchers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!