Mocking the dependencies

While executing the unit test cases on a set of scenarios, it gets complicated when some of your code components are extensively using any framework/dependent API as part of the component building. The following diagram shows how a Unit (component) can work with its dependency in real life but with Mock Dependency during a Unit Test:

 

With the help of mock dependency, the key framework/infrastructure dependencies can be mocked and the components targeted for unit testing can be successfully tested without having the actual dependency elements available during the unit test.

Moreover, for the continuous integration processes wherein the unit tests are configured to automatically execute on all the targeted components on the CI job run, the infrastructure dependencies may not be available or accessible to the continuous integration servers. In such scenarios, the mock dependency elements greatly help in overcoming the infrastructure dependencies for the tests to execute, as explained here.

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

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