Mock objects

A mock is a stub on steroids. It is a stub and much more. Like a stub, a mock object also returns values that are premeditated. Apart from this, a mock object can also be programmed with expectations about the number of times the mock is called and in what order it is invoked. The use of mock objects leads to tests that test specific details about the interaction between the classes without the use of the actual class.

Expectations

Expectations are set on mock objects to define their behavior. Expectations are also a way of asserting that the class under test is working as expected. Exceptions can set expected responses, sequences in which methods should be called, or any errors that were expected. In general, the expectations just ...

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.