This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

annotations override xml

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Craig Walls
author
Ranch Hand
Posts: 363
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic