【发布时间】:2018-04-11 14:45:32
【问题描述】:
我使用 cdi-unit 库测试类。 测试类:
@RunWith(CdiRunner.class)
public class IAktResponseMapperTest {
@Inject
private ITestCDI testCDI;
@Test
public void testCDI(){
testCDI.testCDI();
}
}
ITestCDI 接口:
public interface ITestCDI {
void testCDI();
}
TestCDI 类:
@ApplicationScoped
public class TestCDI implements ITestCDI {
public void testCDI() {
System.out.println("testCDI");
}
}
所以,运行这个测试我得到了错误:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ITestCDI with qualifiers @Default
at injection point [UnbackedAnnotatedField] @Inject private ru.nwth.pio.personal_area.accounting.mapper.IAktResponseMapperTest.testCDI
at ru.nwth.pio.personal_area.accounting.mapper.IAktResponseMapperTest.testCDI(IAktResponseMapperTest.java:0)
但是如果我直接注入TestCDI类而不是接口ITestCDI,就可以了。如何使界面正常工作?感谢您的帮助!
【问题讨论】:
标签: java-8 cdi junit4 cdi-unit