title: Google guice module configuration for unit testing
body: <p>I'm trying to use google guice for dependency injection however I can't seem to wire everything togheter.</p>
  
  <p>In my web.xml I defined the guiceFilter and the guiceListener like so:</p>
  
  <pre><code>   &lt;filter&gt;
      &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.google.inject.servlet.GuiceFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;backend.listener.GuiceConfigListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>the config listener is basicly pretty simple:</p>
  
  <pre><code>@Override
  protected Injector getInjector(){
      return Guice.createInjector(new ServletModule(), new ArtsModule());
  }
  </code></pre>
  
  <p>and the ArtsModule at this moment just has one binding like so:</p>
  
  <pre><code>@Override
  protected void configure(){
      bind(ArtsDAO.class).to(ArtsDAOGae.class);
  }
  </code></pre>
  
  <p>I then continue to do a field injection of the ArtsDao in a service class:</p>
  
  <pre><code>@Inject
  private ArtsDAO artsDAO;
  </code></pre>
  
  <p>But when I try to build my project (which is a maven build) I get a NPE on the artsDAO field, this most likely happens because the unit tests aren't running in a web environment.</p>
  
  <p>Can anyone advice me on how to configure the guice bidings so that they are picked up during unit testing?</p>
  
  <p>Thanks</p>