无法创建类 org.jboss.arquillian.test.impl.EventTestRunnerAdaptor 的新实例

Posted

技术标签:

【中文标题】无法创建类 org.jboss.arquillian.test.impl.EventTestRunnerAdaptor 的新实例【英文标题】:Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor 【发布时间】:2014-07-25 19:06:40 【问题描述】:

我有这个 pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>company</groupId>
        <artifactId>trick-services-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>tricker-services-webapp</artifactId>
    <packaging>war</packaging>
    <name>trick-rest</name>
    <!-- <build> <finalName>trick</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> <configuration> <outputDirectory>../vagrant/deployments</outputDirectory> 
        </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.17</version> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> 
        <filtering>true</filtering> </resource> </resources> <testResources> <testResource> 
        <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> 
        </testResources> </build> -->

    <build>
        <defaultGoal>test</defaultGoal>
        <plugins>
            <!-- The compiler plugin enforces Java 1.6 compatibility and controls 
                execution of annotation processors -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
            </plugin>
        </plugins>
    </build>



    <dependencyManagement>

        <dependencies>
            <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-bom</artifactId> 
                <version>1.0.0.Alpha2</version> <scope>import</scope> <type>pom</type> </dependency> -->
            <dependency>
                <groupId>org.jboss.shrinkwrap.resolver</groupId>
                <artifactId>shrinkwrap-resolver-bom</artifactId>
                <version>2.0.0-alpha-5</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.0.3.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-bom</artifactId> 
            <version>1.0.0.Alpha2</version> </dependency> -->
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-junit</artifactId>
            <scope>test</scope>
            <version>1.0.0.Alpha5</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <!-- F -->

        <!-- Jax RS and REST API Related Dependencies -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
        </dependency>

        <!-- Used by Jetty only. -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>company</groupId>
            <artifactId>tricking-service</artifactId>
            <version>$project.version</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- <dependency> <groupId>com.wordnik</groupId> <artifactId>swagger-jaxrs_2.9.1</artifactId> 
            </dependency> -->
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-core_2.9.1</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-warp-impl</artifactId> 
            <scope>test</scope> </dependency> -->

        <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-impl-resteasy</artifactId> 
            <scope>test</scope> </dependency> -->
        <!-- <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-embedded-3.1</artifactId> 
            <version>1.0.0.CR3</version> <scope>test</scope> </dependency> <dependency> 
            <groupId>org.glassfish.main.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> 
            <version>3.1.2</version> <scope>provided</scope> </dependency> -->

        <!-- <dependency> <groupId>org.jboss.as</groupId> <artifactId>jboss-as-arquillian-container-managed</artifactId> 
            <version>7.1.1.Final</version> <scope>test</scope> </dependency> -->

    </dependencies>
    <profiles>
        <profile>
            <id>arquillian-glassfish-embedded</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                    <version>1.0.0.CR3</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.main.extras</groupId>
                    <artifactId>glassfish-embedded-all</artifactId>
                    <version>3.1.2</version>
                    <scope>provided</scope>
                </dependency>
                <!-- Enable dependency if you want to use H2 -->
                <!-- Also update glassfish-resources.xml to use H2 connection information -->
                <!-- <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> 
                    <version>1.3.166</version> <scope>test</scope> </dependency> -->
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-glassfish-embedded</directory>
                    </testResource>
                </testResources>
                <plugins>
                    <!-- The surefire plugin is configured to pass a system property to 
                        GlassFish to retarget the derby log file -->
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.12</version>
                        <configuration>
                            <systemPropertyVariables>
                                <java.util.logging.config.file>
                                    $project.build.testOutputDirectory/logging.properties
                                </java.util.logging.config.file>
                                <derby.stream.error.file>
                                    $project.build.directory/derby.log
                                </derby.stream.error.file>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- Make sure that the default Derby database is started when you start 
                the GlassFish instance -->
            <!-- You can start the database using this command: asadmin start-database -->
            <id>arquillian-glassfish-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-web-6.0</artifactId>
                    <version>3.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>xalan</groupId>
                            <artifactId>xalan</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-glassfish-remote-3.1</artifactId>
                    <version>1.0.0.CR3</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-glassfish-remote</directory>
                    </testResource>
                </testResources>
            </build>
        </profile>
        <profile>
            <id>arquillian-jbossas-managed</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-web-6.0</artifactId>
                    <version>3.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>xalan</groupId>
                            <artifactId>xalan</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-managed</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.protocol</groupId>
                    <artifactId>arquillian-protocol-servlet</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-jbossas-managed</directory>
                    </testResource>
                </testResources>
                <plugins>
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.jboss.as</groupId>
                                            <artifactId>jboss-as-dist</artifactId>
                                            <version>7.1.1.Final</version>
                                            <type>zip</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>target</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>arquillian-jbossas-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-6.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-remote</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.protocol</groupId>
                    <artifactId>arquillian-protocol-servlet</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-jbossas-managed</directory>
                    </testResource>
                </testResources>
            </build>
        </profile>
    </profiles>
</project>

这是我拥有的一个测试类:

@RunWith(Arquillian.class)
@RunAsClient
public class TrickerResourceTest 
    @Deployment
    public static Archive<?> createDeployment() 
        return ShrinkWrap.create(WebArchive.class, "test.war")
            .addPackage(Tricker.class.getPackage())
            .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    

     @Test
      public void getAllTrickers() throws Exception
      
         Assert.assertTrue(true);
      


这是我的 arquillian.xml

<arquillian xmlns="http://jboss.org/schema/arquillian"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <container qualifier="jbossas-managed" default="true">
        <configuration>
            <property name="jbossHome">target/jboss-as-7.1.1.Final</property>
        </configuration>
    </container>
</arquillian>

这是我的测试持久性:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="test">
        <!-- Use this jta-data-source if you're testing on JBoss AS 7.1 (setup by jbossas-ds.xml) -->
        <jta-data-source>jdbc/arquillian</jta-data-source>

        <!-- Use this jta-data-source if you're testing on JBoss AS 7.0 -->
        <!-- Optionally, you can setup a DataSource with this name in your JBoss AS 7.0 installation -->
        <!-- 
        <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
        -->
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

这是我的 jbossas-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.jboss.org/ironjacamar/schema
        http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <datasource enabled="true"
        jndi-name="jdbc/arquillian"
        pool-name="ArquillianEmbeddedH2Pool">
        <connection-url>jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1</connection-url>
        <driver>h2</driver>
    </datasource>
</datasources>

我想在 JBoss 上运行它,所以我说的是 cmd:

mvn test -Parquillian-jbossas-managed

我得到的错误是:

Tests in error:
  com.company.Trickservice.webapp.api.test.TrickerResourceTest: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

cmd 上的完整堆栈跟踪:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.company.trickservice.webapp.api.test.TrickerResourceTest
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/Elban/Documents/trick-services/web/target/classes/logback.xml]
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/Elban/Documents/trick-services/web/target/classes/logback.xml]
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/C:/Users/Elban/.m2/repository/company/tricking-core/0.0.1-SNAPSHOT/tricking-co
re-0.0.1-SNAPSHOT.jar!/logback.xml]
12:36:29,550 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
12:36:29,556 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
12:36:29,563 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
12:36:29,573 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:36:29,609 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to TRACE
12:36:29,609 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
12:36:29,610 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
12:36:29,610 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@74af72d8 - Registering current configuration as safe fallback point

12:36:29.617 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.354 sec <<< FAILURE!

Results :

Tests in error:
  com.company.trickservice.webapp.api.test.trickerResourceTest: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.390s
[INFO] Finished at: Thu Jun 05 12:36:30 CEST 2014
[INFO] Final Memory: 47M/300M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project tricker-services-webapp: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\Elban\Documents\trick-services\web\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
C:\Users\Elban\Documents\trick-services\web>

如果您需要更多信息,请告诉我。

【问题讨论】:

你有完整的堆栈跟踪吗? 尝试完全删除这个 org.jboss.arquillian:arquillian-junit:1.0.0.Alpha5 依赖项。 现在我收到此错误:测试错误:com.company.trickservice.webapp.api.test.trickerResourceTest:无法部署到容器:“JBAS014671:服务失败”=> “ jboss.persistenceunit.\"test.war#test\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"test.war#test\": 无法启动服务" 这是来自 AppServer 的部署错误,所以.. 你的持久性设置有问题吗? server.log 可能包含更多详细信息。 问题的正确答案是here 【参考方案1】:

我昨天找到了解决方案,所以我会在这里回答,以防其他人抛出此错误:

问题是我的 Tricker 类有一个 TrickerType 类型的字段,我没有将它包含在 Depoyment 中。所以,这解决了我的问题:

@RunWith(Arquillian.class)
@RunAsClient
public class TrickerResourceTest 
    @Deployment
    public static Archive<?> createDeployment() 
        return ShrinkWrap.create(WebArchive.class, "test.war")
            .addPackage(Tricker.class.getPackage(), TrickerType.class.getPackage())
            .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    

     @Test
      public void getAllTrickers() throws Exception
      
         Assert.assertTrue(true);
      


【讨论】:

为避免将来出现此类问题,您可以通过执行archive.addPackages(true, new ExcludeRegExpPaths(".*Test.class$"), PROJECT_ROOT_PACKAGE); 一次性添加所有类,如果 PROJECT_ROOT_PACKAGE 是您的根包,这将添加所有类。它需要一个不包含测试类的过滤器,因为在执行的那一刻,它们将是可用的。【参考方案2】:

我对 arquillian-bom 的 1.1.4.Final 和 1.0.3.Final 有同样的问题

<dependency>
  <groupId>org.jboss.arquillian</groupId>
  <artifactId>arquillian-bom</artifactId>
  <version>$org.jboss.arquillian.bom.version</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

我已经评论了它,我正在使用:

<org.jboss.arquillian.junit.version>1.0.0.CR7</org.jboss.arquillian.junit.version>
<org.jboss.arquillian.spi.version>1.0.0.Alpha5</org.jboss.arquillian.spi.version>   

<dependency>
  <groupId>org.jboss.arquillian.junit</groupId>
  <artifactId>arquillian-junit-container</artifactId>
  <version>$org.jboss.arquillian.junit.version</version>
  <scope>test</scope>
</dependency>                       
<dependency>
  <groupId>org.jboss.arquillian.protocol</groupId>
  <artifactId>arquillian-protocol-servlet</artifactId>
  <version>$org.jboss.arquillian.junit.version</version>
  <scope>test</scope>
</dependency>       
<dependency>
  <groupId>org.jboss.arquillian</groupId>
  <artifactId>arquillian-spi</artifactId>
  <version>$org.jboss.arquillian.spi.version</version>
  <scope>test</scope>
</dependency>       

所以降级到 arquillian-bom 的 1.0.0.CR7 应该可以修复它

<org.jboss.arquillian.bom.version>1.0.0.CR7</org.jboss.arquillian.bom.version>  

【讨论】:

感谢您指出几个版本的问题。我搜索了我的错误将近一个小时 - 我需要做的就是将 arquillian 从 1.1.8 升级到 1.1.11,现在可以按预期工作。【参考方案3】:

有时,当使用 IDE 快捷方式注释掉代码时,IDE 可能会添加三个“-”而不是两个,例如:

<!--        <property name="host">172.33.22.11</property>
       <property name="port">8080</property>--->

这是在我的 arquillian.xml 中

【讨论】:

【参考方案4】:

我的解决方法不是直接导入arquillian-persistence-dbunit,而是arquillian-persistence,其中也包含前者:

<dependency>
    <groupId>org.arquillian.universe</groupId>
    <artifactId>arquillian-persistence</artifactId>
    <version>1.5.0.0</version>
    <type>pom</type>
    <scope>test</scope>
</dependency>

【讨论】:

以上是关于无法创建类 org.jboss.arquillian.test.impl.EventTestRunnerAdaptor 的新实例的主要内容,如果未能解决你的问题,请参考以下文章

无法从字符串创建我的 CIFilter 类

无法创建类 ViewModel 的实例

无法创建类 ViewModel kotlin 的实例

JFinal中配置类实例无法创建的问题

Mongo自定义序列化程序导致无法创建抽象类

无法创建具有特定数量的类标签的熊猫数据框