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?
}
Also, you can use JUnit if you want to, and import the ScalaTest or the specs2 matchers inside your test cases if you want more expressivity for your assertions.
When you mark a test class with a tag annotation, ScalaTest will mark each test defined in that class with that tag. Thus, marking the SetSpec in the above example with the @Ignore tag annotation means that both tests in the class will be ignored.
assert is a precondition in Scala that evaluates a boolean expression as true or false. It's generally used to validate the execution of the program during runtime. We can see assert is used commonly in testing the functionality of programs.
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?
Does this work, assuming the case you want is DesiredCase
?
result match {
case DesiredCase(values) => {
values.foo should be ("bar")
}
case _ => {
fail("Not DesiredCase")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With