Monday, July 9, 2012
List out the technical details of mock object?
Posted by
Sunflower
at
7/09/2012 04:07:00 PM
0
comments
Labels: Application, Behavior, Conditions, Data, Details, Developers, Fake, Functionality, Information, Methods, Mock objects, Objects, Requirements, Simulate, Software testing, Stubs, Systems, Technical
|
| Subscribe by Email |
|
Monday, May 21, 2012
What is the use of a mock object in test driven development?
What are Mock Objects?
Use of Mock Object in TDD
Posted by
Sunflower
at
5/21/2012 04:47:00 PM
0
comments
Labels: Application, Behavior, Conditions, Data, Developers, Fake, Functionality, Information, Methods, Mock objects, Objects, Requirements, Simulate, Software testing, Systems, TDD, Test Driven Development, Unit Testing
|
| Subscribe by Email |
|
Saturday, April 14, 2012
What are the advantages and limitations of a mock object?
Mock objects are nowadays quite popular with the testers. The mock objects are now being used widely for conducting unit testing and also in many software development processes like the test driven development.
- The mock objects are known for their mimicking behaviour of the other non mock or original objects for which they have been created.
- The mock objects are used under the context of the object oriented programming.
- They are nothing but the fake objects that are simulated in a way as to mimic the behavior of the real objects in a way that is properly controlled and defined.
- The behavior of most of the non mock or real objects is tested against the behavior of a mock object.
- You can compare the mock object with a crash test dummy that is used by the car designers to the impact of the vehicle on the human body.
Reasons for Use
Few of them have been mentioned below:
1. The real object provides non deterministic result like current temperature and time.
2. The real object has the states that cannot be easily recreated or reproduced such as a network error.
3. The real object is quite slow such as a data base that needs initializing before the commencing of the test.
4. The real object does not exist currently.
5. The real object tends to change its behaviour.
6. The real object is to include the information for the testing purposes.
Advantages of Mock Object
- One of the characteristic of the mock objects is that they possess the same interface as that of the real objects that they mimic.
- With such an arrangement the client stays unaware of whether he is using the real object or the mock object.
- With the use of mock objects it becomes easy for the programmer to specify which and all methods will be invoked and in what order and it can also be specified which parameters are to be passed to the mock objects.
- All this is done by using the mock object frame works.
- The mock objects can even mimic the behaviour of the complex objects, for example the network socket.
- The use of mock objects can help the programmer in various ways.
- The programmer can determine whether the object that is under test responds well to the variety of situations it is put in works properly or not.
Limitations of Mock Object
- Use of mock objects can lead to close coupling of the several unit tests similar to that in the actual implementation of the code that is under testing.
- If a programmer is using the mock object frame work, the order of and number of times the mock methods are to be invoked on a mock object can be specified.
- If the code is subsequently refactored, it may fail even though the contract of the previous implementation is followed in the method.
- The unit tests are known to test only the external behaviour of the mock methods rather than testing its internal implementation.
- Therefore, maintenance needed for the tests increases if there is an overuse of the mock objects.
- Mock objects need to model the real objects perfectly well which becomes difficult if the real object has not been written yet.
Posted by
Sunflower
at
4/14/2012 12:19:00 PM
0
comments
Labels: Advantages, Behavior, Characteristics, Code, Complex, Dummy, Limitations, Methods, Mock objects, Objects, OOP, Programmer, Re-factoring, Simulate, Software testing, Testers, Tests, Unit Testing
|
| Subscribe by Email |
|
Friday, April 13, 2012
What is a mock object? What are the reasons for use?
Perhaps most of us have heard about mock objects but do not know what it is actually! This article is dedicated to the mock objects and the reasons for which they are used.
First we will clear up the concept of mock object and then we will move on to the reasons for its use. Mock objects are a concept of the object oriented programming.
" Mock objects are defined as some simulated objects that have the ability to mimic the behavior of the real objects in a defined and controlled way. Mock objects are used by a programmer or developer to check another object by testing it against the mock object."
Reasons for use of mock objects
- Mock objects as we discussed above are able to perfectly simulate the behaviour of real or we can say non- mock object be it very simple or very complex.
- This property of the mock objects make them an essential and convenient tool for carrying out an effective unit testing which involves testing of the software program modules in isolation.
- It should not be mistaken that the mock objects are used in the place of the original non mock objects.
- They are used in their place only during the testing phase and that too when it is almost impossible and impractical to incorporate the real object in to the created unit tests.
- In some of the cases it is required the presence of some object for testing another one. In such cases the mock objects play a very important role.
Characteristics of Mock Object
Below mentioned are some characteristics which if are present in a non mock object, it is important that you use a mock object in its place:
1. If the object supplies non deterministic results such as the current temperature and current time etc.
2. If the object is having states that are somewhat difficult to be reproduced and recreated such as a network error and so on.
3. If the object is too slow i.e., if it is having a complete data base which requires initializing before the starting of the test.
4. If the object does not exist in practical.
5. If the object tends to change its behavior.
6. If the object currently does not exists.
7. If the object requires including the methods and information regarding the testing purposes but not its actual tasks.
8. If the object is difficult to set up.
9. If the object is a user interface.
10. If the object cannot be queried.
We will give an example so that the mock object concept becomes clear to you!
- Consider your mobile alarm clock which causes an alarm bell to ring at the time that you specify.
- Suppose it gets the current time from somewhere outside, then how do you test this mobile alarm?
- You will have to wait till the alarm bell goes off till that specified time to check whether or not the mobile alarm is working correctly or not.
- Mock objects are sometimes used as mediators.
- In such cases a mock domain comes in to play rather than the actual domain.
Features of Mock Object
Below mentioned are some of the features of a mock object:
- Easy to create
- Easy to set up
- It is quick
- Deterministic
- Easy to cause behavior
- Does not have any direct user interface
- Can be queried directly
The mock objects did not come in to existence in a single day. It took a whole lot of days to experiment, discuss and collaborate and put forward the idea of using a mock object.
Posted by
Sunflower
at
4/13/2012 11:30:00 PM
0
comments
Labels: Behavior, Characteristics, Create, Data, Easy, Errors, Features, Interface, Mock, Mock objects, Network, Phases, Queries, Reasons, Software testing, Stimulation, Tasks, Uses
|
| Subscribe by Email |
|