Subscribe by Email


Monday, May 21, 2012

What is the use of a mock object in test driven development?


Over the years the idea of the mock object was materialized and today they are being used in numerous testing and development methodologies. Nowadays mock objects find their use in many testing methodologies like the unit testing and also in development processes such as the test driven development process. 
This article is focused up on the use of a mock object in the test driven development process. But, before moving further we shall give a brief discussion regarding the concepts of the mock object so that understanding the use of mock object in the test driven development becomes easy for you. 

Mock objects are known as the fake objects that in a way simulate the behaviour of an original or to say a non mock object whenever any of the following conditions are prevalent:
     
     1. If the non mock supplies non deterministic output.
     2. If the non mock object is difficult to be reproduced or recreated.
     3. If the non mock object is quite slow i.e., is using a complete data base.
     4. If the non mock object tends to change its behaviour.
     5. If the non mock object does not yet exists.
     6. If the non mock object demands information and methods exclusive to the testing purposes.

   

What are Mock Objects?


- Mock objects are nothing but fake objects but with a little more purpose of testing the other non mock objects with the method implementations having assertions of their own. 
- They are employed for the examination and verification of the context of each and every method call.
- Apart from this, they are also used to determine the order in which the methods are called and implemented using data that was passed as the arguments in the method calls.
Mock settings are an effective means for ensuring that an exception is generated by the software system or application when the subsequent calls to it are made like it may hang, fail or crash etc. 
With the mock settings, it has become possible to test the client behaviors against all the realistic faulty conditions as well as they can be developed also in the back end sub systems. 
- Without the use of mock objects it will be too difficult to test these conditions. 
- The mock system provides a simple and flexible way to test the realistic fault conditions since proper consideration is given to them.
- With the mock methods it has become easy to add entries to a public log string. 

Use of Mock Object in TDD


Now coming to the use of mock objects in the test driven development, mock objects are used in 
the test driven development during the writing of the software. 

- With the help of mock objects the programmers and developers are able to write and unit test functionality in a defined area by using the mock objects that provide all the interface requirements of the complex real objects rather than using the complex collaborating and underlying classes and objects. 
- With the help of mock objects the programmers are able to focus properly on the testing of the behavior of the SUT or system under test. 
- They don’t have worry about the objects on which it is dependent. 
- There are some practical speed issues also involved with the use of mock objects in the test driven development apart from the complexity issues.
- To develop a realistic piece of software employing the test driven development may require hundreds of unit tests. 
- If any communication is developed between these unit tests and the data bases, networked systems and web services, then it is possible that the suite of unit tests will become quite slow. 


No comments:

Facebook activity