aspose file tools*
The moose likes Spring and the fly likes how dependency injection easy unit testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how dependency injection easy unit testing" Watch "how dependency injection easy unit testing" New topic
Author

how dependency injection easy unit testing

sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1199
how dependency injection reduce unit testing effort?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

DI allows the substitution of implementations. For example, you could create a service that always throws a database exception wrapper to simulate error conditions in your mainline code. This allows you to test your application's error handling/flow.
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
reduce unit testing effort?
Who said that? o_O
For example, you could create a service that always throws a database exception wrapper to simulate error conditions in your mainline code. This allows you to test your application's error handling/flow.
Mock-frameworks are about this issue.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, mock frameworks *create* the object that will be injected.

Without the ability to inject an object mocking is not terribly helpful.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
It makes testing easier, we could inject mock objects via XML without changing any source code.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how dependency injection easy unit testing