File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes annotations override xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "annotations override xml" Watch "annotations override xml" New topic
Author

annotations override xml

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

It looks like Annotations override XML configuration? This caught me by surprise because I would expect an external configuration to allow for overriding an internal one. How do you force mock injection for testing? Or do you do all testing at a lower level so there isn't a need to use Spring to inject the mocks?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 335
    
    5
Let me make this abundantly clear (because I've run into *so* many people lately who ask a similar question):

For unit-testing, Spring shouldn't be involved at all! Spring-style dependency injection along with interface-driven development results in classes that are loosely coupled and easier to test in isolation because dependencies can be given as mocks in tests. But your tests should be wiring those mocks in themselves without Spring being involved.

Integration testing, on the other hand, is where Spring can be involved. In that case, let Spring wire up everything the same way it would in a production situation...because that's what you want to test anyway.


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Craig Walls wrote:For unit-testing, Spring shouldn't be involved at all!

I agree. Good to point this out.

Craig Walls wrote:Integration testing, on the other hand, is where Spring can be involved. In that case, let Spring wire up everything the same way it would in a production situation...because that's what you want to test anyway.

Not necessarily. Integration testing occurs on both the local machine and the deployed/remote environment. The remote environment mirrors production and then everything should be exactly the same. Locally, I may not want some things to run depending on what I have available. Without Spring, I solve this with a property file that says whether than functionality should be run. With Spring, I can choose to continue using the property file or wire things differently. There are some advantages to the property file approach in that I can turn off those features if they are broken in the remote environment. I was just wondering if Spring could do it for me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I agree; Spring shouldn't be involved in the unit testing--wiring should be done by hand.

For integration testing, however, we've often used an environment-specific Spring config (and occasionally test suite-specific, but rarely).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: annotations override xml