This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Spring and the fly likes Dependency Injection & Testability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Dependency Injection & Testability" Watch "Dependency Injection & Testability" New topic
Author

Dependency Injection & Testability

shanthi naidu
Ranch Hand

Joined: Nov 13, 2008
Posts: 39
Hi all,

Dependency injection is simply a good idea and it helps with: testability


Please can anyone tell me how dependency injection helps with testability

Thanks,
Shanthi Naidu
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, let's start this way--what's your understanding of what dependency injection is? Can you think of any reasons it might make testing easier?
shanthi naidu
Ranch Hand

Joined: Nov 13, 2008
Posts: 39
well with dependency injection we can inject the mock objects first till we get the required output and then inject the original objects ... in this way testing became flexible with dependency injection??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's probably the biggest testing advantage, yes--it allows us to choose what exactly to test.
 
Don't get me started about those stupid light bulbs.
 
subject: Dependency Injection & Testability