简体   繁体   English

在安全测试阶段需要类路径,而 arquillian 无法访问

[英]classpath needed during surefire test phase with arquillian not accessible

Scenario:设想:

I am currently trying to develop unit test inside java ee application using arquillian. 我目前正在尝试使用 arquillian 在 java ee 应用程序中开发单元测试。 As a test container I use a remote container running on a wildfly server. 作为测试容器,我使用在 Wildfly 服务器上运行的远程容器。 The setup is working for test as long as the source classes needed are inside the test directory. 只要所需的源类位于测试目录中,该设置就可以进行测试。

Problem:问题:

Once the classes I want to perform test upon are outside the test directory the class loader does not recognize them anymore and I can no longer add them to the micro-deployment using shrinkWrap as I have done previously. 一旦我要执行测试的类在测试目录之外,class 加载器就不再识别它们,我不能再像以前那样使用 shrinkWrap 将它们添加到微部署中。

what am I doing wrong, what am I forgetting?我做错了什么,我忘记了什么? I feel like this could be a very simple setup problem inside my project, as I am new to maven and java ee as well.我觉得这可能是我项目中一个非常简单的设置问题,因为我也是 maven 和 java ee 的新手。 As the setup seems to be working as long as all resources are inside the test directory I am assuming that the error is not a dependency problem but rather a problem with my project setup.只要所有资源都在测试目录中,设置似乎就可以工作,我假设错误不是依赖问题,而是我的项目设置的问题。 Its my first question here on stackoverflow, please exuse any shortcomings on my side:D这是我在stackoverflow上的第一个问题,请原谅我的任何缺点:D

Error message错误信息

 Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.JavaArchive de.mathplan.moses.core.studiengang.model.StudiengangTest.createDeployment() at org.jboss.shrinkwrap.api.asset.ClassLoaderAsset.<init>(ClassLoaderAsset.java:70) at org.jboss.shrinkwrap.impl.base.URLPackageScanner.foundClass(URLPackageScanner.java:165) at org.jboss.shrinkwrap.impl.base.URLPackageScanner.handle(URLPackageScanner.java:157) at org.jboss.shrinkwrap.impl.base.URLPackageScanner.handle(URLPackageScanner.java:145) at org.jboss.shrinkwrap.impl.base.URLPackageScanner.scanPackage(URLPackageScanner.java:113) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addPackage(ContainerBase.java:1520) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addPackages(ContainerBase.java:1497) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addClasses(ContainerBase.java:1358) at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addClass(ContainerBase.java:1285) at de.mathplan.moses.core.studiengang.model.StudiengangTest.createDeployment(StudiengangTest.java:18) ]]></error>

Arquillian Dependencies Arquillian 依赖项

<.-- inside profile --> <dependency> <groupId>org.wildfly.arquillian</groupId> <artifactId>wildfly-arquillian-container-remote</artifactId> <version>3.0.1.Final</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <version>1.7.0.Alpha5</version> <scope>test</scope> </dependency> <.-- client deployment APIs for communicating with the container process --> <dependency> <groupId>org.jboss.arquillian.protocol</groupId> <artifactId>arquillian-protocol-servlet</artifactId> <version>1.4.0.Final</version> <scope>test</scope> </dependency> <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>1.4.0.Final</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement>

You have to configure the file arquillian.xml that is stored inside the src/test/resources folder.您必须配置存储在 src/test/resources 文件夹中的文件 arquillian.xml。

A sample of this file is the following:此文件的示例如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2017, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<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">

    <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
    <defaultProtocol type="Servlet 3.0" />

    <!-- Uncomment to have test archives exported to the file system for inspection -->
    <!--<engine>
        <property name="deploymentExportPath">target/</property>
    </engine>-->

    <!-- Example configuration for a managed WildFly / JBoss EAP instance -->
    <container qualifier="managed">
        <!-- By default, Arquillian will use the JBOSS_HOME environment variable to find the WildFly / JBoss EAP installation.
             If you prefer not to define the JBOSS_HOME environment variable, alternatively you can uncomment the
             following `jbossHome` property and replace EAP_HOME with the path to your WildFly / JBoss EAP installation. -->
        <!--<configuration>
            <property name="jbossHome">EAP_HOME</property>
        </configuration> -->
    </container>
    
    <!-- Example configuration for a remote WildFly / JBoss EAP instance -->
    <container qualifier="remote">
        <!-- Arquillian will deploy to this WildFly server. -->
        <configuration>
            <property name="managementAddress">127.0.0.1</property>
            <property name="managementPort">9990</property>
            <!-- If deploying to a remote server, you have to specify username/password here -->
            <!-- <property name="username">admin</property>
            <property name="password">admin</property> -->
        </configuration>
    </container>
</arquillian>

The qualifier "remote" inside arquillian.xml is used when configuring maven-failsafe-plugin as follow:配置 maven-failsafe-plugin 时使用 arquillian.xml 中的限定符“remote”,如下所示:

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${version.failsafe.plugin}</version>
        <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <!-- Configuration for Arquillian: -->
            <systemPropertyVariables>
                <!-- Defines the container qualifier in "arquillian.xml" -->
                <arquillian.launch>remote</arquillian.launch>
            </systemPropertyVariables>
        </configuration>
    </plugin>

To run your integration test you can use:要运行集成测试,您可以使用:

$ mvn verify

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM