I'm looking for best practices for setting up unit and integration tests using Spring.
I usually use 3 kind of tests:
- "real" unit tests (no dependencies)
- tests run either as "unit" test (in-memory db, local calls, mock objects,...) or as integration test (persistent db, remote calls,...)
- tests run only as integration tests
Currently I only have tests of the second category, which is the tricky part. I set-up a base test class like:
@ContextConfiguration(locations = { "/my_spring_test.xml" })
public abstract class AbstractMyTestCase extends AbstractJUnit4SpringContextTests
And "unit" tests like:
public class FooTest extends AbstractMyTestCase
with autowired attributes.
What's the best way to run the test in a different (integration test) environment? Subclass the test and override the ContextConfiguration?
@ContextConfiguration(locations = { "/my_spring_integration_test.xml" })
public class FooIntegrationTest extends FooTest
Would this work (I cannot currently easily test it here)? The problem with this approach is that "@ContextConfiguration(locations = { "/my_spring_integration_test.xml" })" is duplicated a lot.
Any suggestions?
Regards, Florian