Assertions and Unit Testing
Two important ways to check that the behavior of the software you write is as you expect are assertions and unit tests. In this chapter, we'll show you several options you have in Scala to write and run them.
Assertions in Scala are written as calls of a predefined method assert. The expression assert(condition) throws an AssertionError if condition does not hold. There's also a two-argument version of assert. The expression assert(condition, explanation) tests condition, and, if it does not hold, throws an AssertionError that contains the given explanation. The type of explanation is Any, so you can pass any object as the explanation. The assert method will call toString on it to get ...