0

我想用 DeltaSpike 实现 CDI 测试。但是当我尝试调用一个依赖于 Faces Context 的函数时,我会产生一个空指针异常。

我需要模拟类还是可以以更好的方式对其进行初始化?

@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
    }
}

非常感谢您的每一次帮助!

4

1 回答 1

0

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

于 2015-07-30T11:26:18.267 回答