Showing posts with label JUnit. Show all posts
Showing posts with label JUnit. Show all posts

Tuesday, March 12, 2013

Testing Java classes with field injections

Dependency injection frameworks in Java give us 3 points of injection: constructor, field and setter methods. Many of us prefer field injection because we can skip writing setter methods and keep the number of lines to a minimum. The downside of field injection is that the class no longer can be used or tested without a dependency injection framework, for instance during unit-testing. In this post, I'm going to look at how we can unit-test a class with field injections.