Just started using ScalaTest and I quite like it.
By just reading the docs I have thus far been unable to figure out whether there is any substantial difference between the can
, should
and must
clauses for a FlatSpec
.
In particular, I'm wondering whether a must
failure is treated any differently from a should
one - or it's just "syntactic sugar" to make the tests better self-documented.
It has been inserted into Scaladoc by pretending it is a trait. 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.
Trait FlatSpec is so named because your specification text and tests line up flat against the left-side indentation level, with no nesting needed. FlatSpec 's no-nesting approach contrasts with traits FunSpec and WordSpec , which use nesting to reduce duplication of specification text.
FunSuite is a Scala testing library with the following goals: Reuse JUnit: FunSuite is implemented as a JUnit runner and tries to build on top of existing JUnit functionality where possible. Any tool that knows how to run a JUnit test suite knows how to run FunSuite, including IDEs like IntelliJ.
should
and must
are the same semantically. But it's not about better documentation, it's basically just down to personal stylistic preference (I prefer must
for example).
can
is a little different. You can't (nomen omen) use it directly as a matcher, it's only available in a test descriptor. Quote from FlatSpec
:
Note: you can use must or can as well as should in a FlatSpec. For example, instead of it should "pop..., you could write it must "pop... or it can "pop....
(the same applies for WordSpec
and the two corresponding fixture classes)
Note that for a short time (in ScalaTest 2.0.x I think), the use of must
was deprecated, however, in 2.1.0, the decision has been reverted:
Resurrected MustMatchers in package org.scalatest. Changed deprecation warning for org.scalatest.matchers.MustMatchers to suggest using org.scalatest.MustMatchers instead of org.scalatest.Matchers, which was the suggestion in 2.0. Apologies to must users who migrated to should already when upgrading to 2.0.
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