I want to logically join two ScalaTest assertions with an OR operator.
The thing is, those two assertions are checking something completely different. There are some examples using or
in similar posts but that is not what I want to do.
Most posts are checking an OR condition on the same variable, i.e.
actual should (be (a [RuntimeException]) or be (a [Thread]))
But I want to join completely different things, i.e.
actual should (be (a [RuntimeException]) or somethingElse should be(0)
However, this instruction does not compile, because or
is not a member of assertion
. I tried several syntaxes with brackets but none of them are compiling :
(count should be(0)) or (isCentroid should be(true))
(count should be(0)) || (isCentroid should be(true))
How can I join those two assertions with OR ?
Failed tests throw TestFailedException
when using matchers, so we could wrap the assertion in Try
and then use standard Scala logical operators like so:
val P1 = Try(count should be(0)).isSuccess
val P2 = Try(isCentroid should be(true)).isSuccess
assert (P1 || P2)
On failure we should see something like:
P1 was false, and P2 was false
ScalaTestFailureLocation: example.HelloSpec at (HelloSpec.scala:29)
org.scalatest.exceptions.TestFailedException: P1 was false, and P2 was false
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다