DeltaSpike CDI Testing + NPE Faces Context

时间:2015-07-24 09:55:48

标签: testing cdi jsf-2.2 deltaspike

我想用DeltaSpike实现CDI测试。但是当我尝试调用依赖于Faces Context的函数时,我会产生一个Null Pointer Exception。

我是否需要模拟课程,还是可以更好地进行初始化?

@RunWith(CdiTestRunner.class)
public class DeltaSpikeTest{

    @Inject
    private WindowContext windowContext;

    @Inject 
    private TestBean testBean;

    @Test
    public void main() {
        this.windowContext.activateWindow("w1");

        testBean.methodThatUsesFacesContext(); // NPE
    }
}

非常感谢每一位帮助!

1 个答案:

答案 0 :(得分:0)

您需要使用MyFaces-Test和DeltaSpike提供的适配器之一。 然后你可以像https://github.com/os890/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/PageBeanTest.java

一样使用对JSF的调用
相关问题