title: Inject an EJB into JUnit test class
body: <p>I defined an <strong>EJB</strong> as follows:</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class Foo {
  
      @Inject
      private Boo boo;
  
      public void doSomething() {
          boo.doOther();
      }
  
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>@Named
  @RequestScope
  public class Boo {
  
      public void doOther() {
          // I do, I do...
      }
  
  }
  </code></pre>
  
  <p>I would like to inject the <code>Foo</code> EJB into a <strong>JUnit test class</strong>:</p>
  
  <pre><code>import org.junit.*
  
  public class FooTest {
  
      @EJB
      private Foo foo;
  
      @Test
      public void doSomethingTest() {
          foo.doSomething();
          assertTrue(true);
      }
  
  }
  </code></pre>
  
  <p>... But this code returns a <code>NullPointerException</code>.</p>
  
  <p>What's wrong? How can I properly define that test by using <strong>Java EE CDI</strong>?</p>