首先,我密集搜索并根据http://jglue.org/cdi-unit-user-guide/产生的东西注入单元测试应该工作得很好。CDI单元@生产不起作用
我的设置:
@RunWith(CdiRunner.class)
public abstract class CdiUnitBaseTest extends DBUnitBaseTest {
@Produces
public EntityManager em() {
return em; //field from base class filled @BeforeClass
}
@Produces
public Logger logger() {
return LogManager.getLogger();
}
}
public class SurveyBeanTest extends CdiUnitBaseTest {
@Inject
private SurveyBean bean;
@Test
public void surveyWithoutParticipation() {
Survey s = new Survey();
s.setParticipation(new ArrayList<Participation>());
boolean result = this.bean.hasParticipated("12ST", s);
Assert.assertFalse(result);
}
}
@Remote(SurveyRemote.class)
@Stateless
public class SurveyBean implements SurveyRemote {
@Inject
private Logger log;
@Inject
private SurveyDao sDao;
@Inject
private ParticipationDao pDao;
...
}
例外:
org.jboss.weld.exceptions.DeploymentException:
异常0: org.jboss.weld 3个例外例外列表.exceptions.DeploymentException:WELD-001408:具有限定符的Logger类型的不满意依赖关系@默认 处于注入点[BackedAnnotatedField] @Inject private at.fhhagenberg.unitTesting.beans.SurveyBean.log ...
这意味着CdiRunner会尝试构建我的SurveyBean并注入记录器,但无法找到要注入的对象,尽管我专门在基类中生成了它(EntityManager也一样)。
任何人都知道如何解决这个问题?
PS:标签我是不允许添加:CDI单元,jglue
听起来很对,今晚会试。谢谢。 – Thomas