Approving case classes in ScalaTest

I see Option support there, but what about custom class classes?

I kind of want to do this:

result match { case SuccessCase(values) => { values.foo should be ("bar") } case FailureCase => // should fail test, but how to say this in ScalaTest? } 
+4
source share
3 answers

You can use fail () to specifically reject testing, as in the case of FailureCase => fail ("err msg"), but I'm not sure I understand what you are after. Perhaps you can show more code or develop to clarify the question?

+4
source

DesiredCase this work if you want you to do this DesiredCase ?

 result match { case DesiredCase(values) => {  values.foo should be ("bar") } case _ => { fail("Not DesiredCase") } } 
+1
source

Bill Venners also suggested writing special matches if you often write such tests:

https://groups.google.com/forum/?fromgroups#!msg/scalatest-users/4MemQiqLzao/_DsBTQWaqfwJ

0
source

All Articles