All of them are test doubles and are used for unit testing.
A dummy object is a fake argument that is not really used and has no effect on the test.
A stub object is an object with hard-coded values to be returned. It has no logic as it is state-oriented. It requires the use of methods like when() to prepare the object.
A fake object has implementation with shortcuts. So it's just a simplified version of the production code. It's usually used in integration testing more than unit testing. For example to access an in-memory version of the production database.
A mock is a behaviour oriented object used to assert interactions. It allows to use methods like verify() to assess the interactions.
Finally, a spy is a behaviour oriented object used to assert interactions, but it's different from the mock, as it delegate and monitor calls to real objects.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.