This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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.