我需要为基于Maven的Web应用程序编写基于JBehave的UAT。 测试已执行,但@Injected类未初始化,敬请尝试开始。基于Maven的项目,JBehave和Selenium未能初始化CDI
我使用jbehave - Maven的插件是这样的:
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>4.1.1</version>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*Stories.java</include>
</includes>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>true</ignoreFailureInView>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
正如我在测试中使用CDI,我需要初始化焊接,因此它与测试工作。但是CDI的初始化不会发生,并且我得到NPE的测试代码。
我声明的依赖性是这样的:
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-weld</artifactId>
<version>4.1</version>
<exclusions>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.3.5.Final</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
什么必须做,初始化CDI测试开始之前?
项目中是否有META-INF/beans.xml文件?如果不是,那么你必须创建它,这里是一个[empty beans.xml](https://gist.github.com/sejersbol/845053)的例子,只需将其复制并粘贴到项目中的资源即可。你如何在Java代码中引导和初始化Weld,你能展示这部分代码吗? – krokodilko
他不能。它在版本1.2中是可选的。 – 2017-09-04 19:56:57