I'd like to use something similar to jUnit's assertEquals
in scalatest.
Does the framework implement it or it does just provide assert
and I should use assertEquals
from jUnit itself?
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).
Overview. ScalaTest is one of the most popular, complete and easy-to-use testing frameworks in the Scala ecosystem. Where ScalaTest differs from other testing tools is its ability to support a number of different testing styles such as XUnit and BDD out of the box.
Regarding to the ScalaTest documentation: A test fixture is composed of the objects and other artifacts (files, sockets, database connections, etc.) tests use to do their work. When multiple tests need to work with the same fixtures, it is important to try and avoid duplicating the fixture code across those tests.
There's the 'assert' approach such as
class EqualsTest extends FunSuite {
test("equals") {
assert(1 === 1)
assert(2 === 2, "The reason is obvious")
}
}
Note the use of triple-equals, which gives much better error messages than double-equals when the test fails. Also, the second case provides a hint to be printed if the test fails. It's best to use this for including some data value that would not otherwise be obvious, e.g. a loop count if testing using a loop.
Then there's the ShouldMatchers approach such as
class EqualsTest extends FunSuite with ShouldMatchers {
test("equals") {
1 should be (1)
}
}
This is often preferred because it reads easily. However, learning to use it is just a bit harder - there are some nooks and crannies in the API. And you can't put in a hint explanation.
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