Reputation: 4100
I see there's support for the Option type, but what about custom case classes?
I sort 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?
}
Upvotes: 6
Views: 3131
Reputation: 1544
Bill Venners also suggested writing a custom matcher if writing these kinds of tests often:
https://groups.google.com/forum/?fromgroups#!msg/scalatest-users/4MemQiqLzao/_DsBTQWaqfwJ
Upvotes: 0
Reputation: 3246
Does this work, assuming the case you want is DesiredCase
?
result match {
case DesiredCase(values) => {
values.foo should be ("bar")
}
case _ => {
fail("Not DesiredCase")
}
}
Upvotes: 2
Reputation: 3669
You can use fail() to fail a test on purpose, as in case FailureCase => fail("err msg"), but I'm not sure I understand what you're after. Perhaps you can show more of the code or elaborate to clarify the question?
Upvotes: 4