Test Double

Recently, I have written quite a bit of mock and stub for our REST API services and integration tests. I had some general ideas before, but I have not really got into mock, stub, fake, etc.

And this is a good opportunity for me to get into them seriously. The following is what I’ve read to get into them.

Good reads:

Some abbreviations:

  • UT: Unit Test(s)
  • SUT: System Under Test
  • Test Double: A term to describe this method of testing. Don’t try to make sense the “double” word here, which confused me for a long time.

More:

Good things to remember at the end:

Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.

Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production.

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test.

Spies are stubs that also record some information based on how they were called. One form of this might be an email service that records how many messages it was sent.

Mocks are pre-programmed with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don’t expect and are checked during verification to ensure they got all the calls they were expecting.

Extracted from https://martinfowler.com/bliki/TestDouble.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s