Mocks

Mocks are essentially programmable spies. Mocks are useful when you want to use the same test double in multiple tests. Mocks have the ability to return whatever values you set them to return. It is important to note that mocks are still not doing any logic. They return the value that is specified and do not check the parameters passed to the function.

Mocks are used in all the situations where dummies, stubs, and spies are used. Mocks are a heavier implementation of a test double, which is why you may not want to use them all the time. Mocks get less reuse than the previous test doubles because a mock's data must be set for each test, whereas a dummy, stub, or spy has a set return value that does not need to be configured. Setting up the test data that gets returned is often more difficult than simply creating a whole stub or spy class.

Mocks are created by making a copy of a class or method and creating a property that can be set as the return value for a method; then, in the method being mocked, the property value is returned. Once created, before each test, the mock's return value must be set.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.244