views:

418

answers:

2

I've been struggling coming up with a good solution to separate my testing data from unit tests (hard coded values). Until it dawned on me that I could create beans with spring and use those beans to hold my data.

Are there any draw backs to coding my unit tests this way? Albeit they run a bit slower seeing as how spring has to configure all the beans and what not.

+2  A: 

Fine practice - one of the prime motivators for dependency injection in my view (easier to unit test)

It will be slower because of the need to bring up the Spring application context, so you might reserve this technique for "integration tests".

Ken Gentle
+2  A: 

For unit tests you can always wire in your beans by hand, as in create and inject them yourself, then leave the Spring wiring for integration tests and production/development.

Hates_