【问题标题】:JUnit test AroundInvoke InterceptorJUnit 测试 AroundInvoke 拦截器
【发布时间】:2016-04-12 08:32:37
【问题描述】:
class AbstractXYZClass{
 ...
 @AroundInvoke
 public Object intercept(InvocationContext ctx) ... {
   log("do intercepting");
   ctx.proceed();
 }
 ...
}

@Stateless
class XYZClass extends AbstractXYZClass{
 ...
 public void iWantToTestThisMethod() {...}
 ...
}

(在服务器上运行此程序,iWantToTestThisMethod() 的拦截工作正常)

在我的单元测试中(使用 Needle ...@ObjectUnderTest(implementation=XYZClass.class)...)@AroundInvoke 没有被调用

我如何在 intercept() 拦截的情况下对 XYZClass::iWantToTestThisMethod 进行 JUnit 测试?

【问题讨论】:

    标签: java junit cdi weld needle4j


    【解决方案1】:

    Needle4j 是一个依赖注入“模拟器”,它不支持高级生命周期和作用域。所以你必须想出一个不同的测试策略。 在注入和验证正确的方法交互时,我会坚持使用 needle4j,但在实际的框架行为测试中切换到 CDI-Unit 或 Arquillian 之类的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多