Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Chapter 14 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. 14.1 Assertions Assertions in Scala are written as calls of a predefined method assert . 1 The expression assert(condition) throws an AssertionError if condition does not hold. There's also a two-argument version of assert . The expres- sion 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 explana-