O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required