How can I perform an OR with ScalaTest

Arthur Attout

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 ?

Mario Galic

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I get my SSDs write speeds to perform normally?

분류에서Dev

Can GLSL perform a recursion formula calculation? Or how can I speed up this formular

분류에서Dev

how can I perform both negative lookahead and negative lookbehind in a single perl regx?

분류에서Dev

How can I use the Find method to perform a case insensitive search on the database field?

분류에서Dev

How Can I perform Integration Testing against Oracle UCM with consistent data?

분류에서Dev

Can I make a launcher shortcut perform different actions based on a condition?

분류에서Dev

How do I perform variable assignment with a loop, and break?

분류에서Dev

How do I perform a proper unsigned right shift in PHP?

분류에서Dev

How do I perform a join in Laravel 5 with a `where` clause?

분류에서Dev

How do I perform a join in Laravel 5 with a `where` clause?

분류에서Dev

How to perform Bulk Upsert

분류에서Dev

awk + how to perform OR in awk

분류에서Dev

How can I run owncloud?

분류에서Dev

How can I organize this array

분류에서Dev

How can I rewrite this a generic?

분류에서Dev

How can I get a RejectedExecutionException

분류에서Dev

How can i manage this request?

분류에서Dev

How can I rotate a Rectangle?

분류에서Dev

How can I get a solution for this?

분류에서Dev

How can I foreach a hashmap?

분류에서Dev

How can I stop the timer?

분류에서Dev

How can I repack JPEG?

분류에서Dev

How i can use a criteria in cicle for i

분류에서Dev

How do I perform the atan2 function in T-SQL?

분류에서Dev

How can I run a desktop in the cloud that I can remotely connect to?

분류에서Dev

If I have apply(i: Int), how can I have map?

분류에서Dev

How to perform HTTPS Calls in Pycurl?

분류에서Dev

How to perform argument parsing in C?

분류에서Dev

cassandra - how to perform table query?

Related 관련 기사

뜨겁다태그

보관