JUnit 4 for CDI Java-SE tests

If just plain unit testing is needed without JEE APIs it's possible to use the AbstractTest

@RunWith(JUnit4.class)
public class SimpleJUnitTest extends org.apache.myfaces.extensions.cdi.test.base.junit4.AbstractTest
{
    @Inject
    private Logger logger;

    @Test
    public void testLogger()
    {
        assertNotNull(this.logger);
        this.logger.info("I'm a JUnit test-case and I can use dependency injection!");
    }
}

JUnit 4 for CDI Java-EE tests

If it's required to test e.g. request scoped beans it's possible to use the AbstractServletAwareTest

@RunWith(JUnit4.class)
public class SimpleJUnitTest extends org.apache.myfaces.extensions.cdi.test.base.junit4.AbstractServletAwareTest
{
    @Inject
    private RequestScopedBean requestScopedBean;

    @Test
    public void testLogger()
    {
        assertNotNull(this.requestScopedBean.getValue());
    }
}

If it's required to test e.g. grouped conversation scoped beans it's possible to use the AbstractServletAwareTest

@RunWith(JUnit4.class)
public class SimpleJUnitTest extends org.apache.myfaces.extensions.cdi.test.base.junit4.AbstractJsfAwareTest
{
    @Inject
    private ViewAccessScopedBean viewAccessScopedBean;

    @Test
    public void testLogger()
    {
        assertNotNull(this.viewAccessScopedBean.getValue());
    }
}

Examples

An example is available here.