Max*_*val 7 testing integration-testing cdi jboss-weld weld
我能够部署一个与 Weld 配合良好的 RESTEasy 应用程序(这意味着我的 CDI 可以工作),但我在集成测试中遇到了一些问题。我收到此错误:
org.jboss.weld.exceptions.DeploymentException:
WELD-001408: Unsatisfied dependencies for type SomeService with qualifiers @Default
Run Code Online (Sandbox Code Playgroud)
测试时:
@RunWith(WeldJUnit4Runner.class)
public class SomeServiceIT {
@Inject
private SomeService service;
@Test
public void test() {
System.out.println(service);
}
}
Run Code Online (Sandbox Code Playgroud)
我日志中的最后一条消息是
DEBUG::WELD-000100: Weld initialized. Validating beans
Run Code Online (Sandbox Code Playgroud)
src/test/resources/META-INF/beans.xml 的内容:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我尝试了该cdi-unit库并且它可以工作,但我需要使用我自己的库WeldJUnit4Runner,目前是:
public class WeldJUnit4Runner extends BlockJUnit4ClassRunner {
private final Weld weld;
private final WeldContainer container;
public WeldJUnit4Runner(Class<?> klass) throws InitializationError {
super(klass);
this.weld = new Weld();
this.container = weld.initialize();
}
@Override
protected Object createTest() throws Exception {
return container.instance().select(getTestClass().getJavaClass()).get();
}
}
Run Code Online (Sandbox Code Playgroud)
我使用weld-se2.4.1.Final 进行测试。
谢谢。
编辑:
所以看来 Weld 只查看 src/test/java (当我将 SomeService 复制到 src/test/java 时,它就可以了)。这很愚蠢,我不会复制所有类来测试它们...如何告诉 Weld 从 src/main/java 检索类?
所以我能够通过src/main/resources/META-INF/beans.xml在现有的基础上创建它来使其工作src/main/webapp/WEB-INF/beans.xml,src/test/resources/META-INF/beans.xml这意味着现在我在同一个项目中有 3 倍完全相同的文件,我觉得这很愚蠢,但我想这就是焊接世界的情况......
感谢大家抽出时间。
编辑:
实际上我只能使用src/main/resources/META-INF/beans.xml(我删除了src/main/webapp/WEB-INF/beans.xml)来部署应用程序
| 归档时间: |
|
| 查看次数: |
1785 次 |
| 最近记录: |