1 Reply Latest reply on Mar 17, 2012 8:10 PM by heyw

    Out of container dependency injection

    dan.j.allen

      I just stumbled over the blog entry Testing Seam 2 based applications with Needle, which naturally piqued my interested. My immediate thought was, "What the heck is Needle?" That led me to the Needle project page. Needle identifies itself as a framework testing Java EE components "outside of the container". It defaults to injecting mocks into injection points, with the option to substitute a real component selectively. (Ike is giving us his angry face hahaha).

       

       

       

      As I've mentioned in several talks, my position on mocks is that they are tacticle. There are times when you do need to sever off part of the real application when the goal is to focus more narrowly on a distinct part of the application...or because the real component is just fubared. So being able to inject a mock can be useful (as an alternative to @Alternative or a replacement class).

       

      Seeing Needle got me thinking that perhaps it's time to graduate the extension example that Aslak put together last fall to autodiscover mock objects and promote them into real components for injection. Shortly after that, we discovered that Rafael Liu also created an extension to promote mock objects into real components (definitely a soldier in Ike's army), which he presented at Devoxx.

       

      In this thread, perhaps we can define some requirements these two extensions touch on. We can then put up an extension git repo, drop in some code and see if we can interest Rafael and/or the Needle team in getting involved. We can also just discuss mocks in general. Where do mocks fit in? What do you think of Needle?

       

      Then there's also the opportunity to compare and contrast a test using Needle vs a test using Arquillian. Those types of comparisons often help us understand where we are and where we can go (it's not a contest).

        • 1. Re: Out of container dependency injection
          heyw

          Hello Dan,

           

          thank you for your opinion about Needle. Of course we are interested to combine the experiences of both worlds.

           

          A few weeks ago I discuss with Ales Justin about a Needle extension for Arquillian. I'm not sure if that makes sense. If a test case based on mock objects and the behaviour are trained with Mockito or EasyMock it is not possible to switch without code modification to a in-container test. On the other hand, with a Arquillian extension it would be much easier to migrate from a mock test to a container test.

           

          In our projects we using currently both frameworks: Arquillian for fine-grained integration tests and Needle for fast unit tests.

           

          I am looking forward to the discussion with the community and the opinions regarding Arquillian, Mock-Objects and Needle.

           

          Regards, Heinz