Active Topics Memberlist Calendar Search Help | |
Register Login |
One Stop Testing Forum : Types Of Software Testing @ OneStopTesting : Unit Testing @ OneStopTesting |
Topic: Inversion of Control pattern for unit testing |
|
Author | Message |
Sameer
Newbie Joined: 23Feb2007 Online Status: Offline Posts: 1 |
Topic: Inversion of Control pattern for unit testing Posted: 23Feb2007 at 4:41pm |
What is Inversion of Control?
Inversion of control pattern is used for loose coupling between components. Components should program to an interface for services they require, this way the actual implementation can be changed at any time. The creation of the object of the actual implementation should not be hard coded in the components. The service consuming component doesn’t know anything about how to create the service providing component. It is the responsibility of the service configurator or the container to inject the dependencies based on some configuration. It is also called dependency injection because the container is creating the dependent objects and injecting them into the component. The dependency injection can be done using constructors or setters. You can either use your own service configurator or use a framework for IOC like spring, hivemind and picocontainer How can it be used for Unit Testing? Because the components are loosely coupled, a component can be tested without depending on other components. When creating an interface the programmer can also create a mock implementation of the interface. The component programmer can test his component by using the mock implementation during the testing, which can be later changed to the actual implementation. Even if you know that there won't be more than one implementation of a service it is still better to create an interface and use IOC, because of its use in Unit Testing. Post Resume: Click here to Upload your Resume & Apply for Jobs |
|
IP Logged | |
Forum Jump |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
© Vyom Technosoft Pvt. Ltd. All Rights Reserved.