• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

annotations override xml

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
reply
    Bookmark Topic Watch Topic
  • New Topic