Tag: cdi unit

由于公共私人领域的矛盾,使用Junit @Rule的CdiUnit测试是不可能的

以下代码段足以重现我的问题: 我将thrown属性设置为public并获取错误org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field 或者我删除public修饰符并获取错误org.junit.internal.runners.rules.ValidationError: The @Rule ‘thrown’ must be public. 我还试图让public修饰符到位,并在类上添加@Dependent注释范围,但得到错误org.jboss.weld.exceptions.DefinitionException: WELD-000046: At most one scope may be specified on [EnhancedAnnotatedTypeImpl] public @Dependent @ApplicationScoped @RunWith 我删除了所有不必要的代码,但这是一个非常复杂的unit testing,通过CDI进行模拟,服务注入,并且一些测试方法预计会引发exception。 import org.jglue.cdiunit.CdiRunner; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; @RunWith(CdiRunner.class) public class FooBarTest { @Rule public ExpectedException […]