Stubs

A stub is an object that yields predefined results based on a predetermined set of inputs. A stub is very restrictive in its usage. If we create a stub that will return "Land Rover Discovery Sports" whenever we call it with string "CK65ZSR", then it will be restricted to only this operation. If we call it with some other string, it wouldn't know what to do. In this case, depending on our implementation of the stub, it may throw an error or return null (or Scala's equivalent of null). There may be a bit of astuteness in the stub so it can remember how many times it has been called and with what parameters. This is done so that we can verify the behavior of the stub.

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.