我使用 cdi-unit 库测试类。测试类:
@RunWith(CdiRunner.class)
public class IAktResponseMapperTest {
@Inject
private ITestCDI testCDI;
@Test
public void testCDI(){
testCDI.testCDI();
}
}
ITestCDI接口:
public interface ITestCDI {
void testCDI();
}
测试CDI类:
@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,就可以了。如何使界面正常工作?感谢帮助!