you can use Matcher#should(Matcher[T])
with Matcher#or[U <: T](Matcher[U])
example,
it("test instanceOf A or B") {
val actual = new Thread()
actual should (be (a [RuntimeException]) or be (a [Thread]))
}
if actual does not match the expected, it errors out with proper messaging,
it("test instanceOf A or B") {
val actual = new String()
actual should (be (a [RuntimeException]) or be (a [Thread]))
}
error
"" was not an instance of java.lang.RuntimeException, but an instance of java.lang.String, and
"" was not an instance of java.lang.Thread, but an instance of java.lang.String
The conventional way, (I'm still in 2000s)
val actual = new Thread()
assert(actual.isInstanceOf[RuntimeException] || actual.isInstanceOf[Thread])
Reference
http://www.scalatest.org/user_guide/using_matchers#logicalExpressions
Is there anyway we can give two conditions in Scalatest using ShouldMatchers