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

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.

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