JUnit 4 for CDI Java-SE tests
If just plain unit testing is needed without JEE APIs it's possible to use the AbstractTest
| Code Block |
|---|
| java |
|---|
| java |
|---|
| title | Simple JUnit 4 test with dependency injection |
|---|
|
@RunWith(JUnit4.class)
public class SimpleJUnitTest extends org.apache.myfaces.extensions.cdi.test.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
...
| Code Block |
|---|
| java |
|---|
| java |
|---|
| title | Simple JUnit 4 test with dependency injection for the JSF API |
|---|
|
@RunWith(JUnit4.class)
public class SimpleJUnitTest extends org.apache.myfaces.extensions.cdi.test.junit4.AbstractJsfAwareTest
{
@Inject
private ViewAccessScopedBean viewAccessScopedBean;
@Test
public void testLogger()
{
assertNotNull(this.viewAccessScopedBean.getValue());
}
}
|
Examples
An example is available here.