【问题标题】:DeltaSpike CDI Testing + NPE Faces ContextDeltaSpike CDI 测试 + NPE Faces 上下文
【发布时间】:2015-07-24 09:55:47
【问题描述】:

我想使用 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
    }
}

我们非常感谢每一个帮助!

【问题讨论】:

    标签: testing cdi jsf-2.2 deltaspike


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 2017-06-13
    • 2014-07-22
    相关资源
    最近更新 更多