Arquillian/JUnit 测试从控制台运行,但不在 Eclipse 内运行

发布于 2024-11-25 15:58:39 字数 1252 浏览 3 评论 0原文

我已经使用一些 JUnit 测试设置了我们的项目,这些测试由 Arquillian 在完整的 JBoss 服务器内(在名为 jboss-remote-6 的配置文件内)运行。我几乎按照 http:// /docs.jboss.org/arquillian/reference/latest/en-US/html/gettingstarted.html

如果我在控制台中执行mvn test,则一切都会正确执行并检查断言。

但是,当我尝试在 Eclipse 中运行 JUnit 测试用例时,它失败并出现以下异常:

org.jboss.arquillian.impl.client.deployment.ValidationException: DeploymentScenario contains targets not maching any defined Container in the registry. _DEFAULT_
    at  org.jboss.arquillian.impl.client.deployment.DeploymentGenerator.validate(DeploymentGenerator.java:95)
    at org.jboss.arquillian.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
(...)

我将此项目的 Maven 配置文件正确设置为“jbossas-remote-6”,如 pom.xml 中所述。我做错了什么? Google 无法针对这一具体问题提供帮助。

此致, 塞巴斯蒂安

I've setup our project with some JUnit tests that are run by Arquillian inside the full JBoss Server (inside a profile called jboss-remote-6). I pretty much did everything as in the manual at http://docs.jboss.org/arquillian/reference/latest/en-US/html/gettingstarted.html.

If I execute mvn test in the console, everything is properly executed and the assertions are checked.

But when I try to run the JUnit test case inside Eclipse, it fails with the following exception:

org.jboss.arquillian.impl.client.deployment.ValidationException: DeploymentScenario contains targets not maching any defined Container in the registry. _DEFAULT_
    at  org.jboss.arquillian.impl.client.deployment.DeploymentGenerator.validate(DeploymentGenerator.java:95)
    at org.jboss.arquillian.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
(...)

I set up the Maven profile for this project correctly to "jbossas-remote-6" as stated in the pom.xml. What am I doing wrong? Google coulnd't help on this specific one.

Best regards,
Sebastian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

椒妓 2024-12-02 15:58:39

为了使这项工作成功,我做了很多事情。我的角色模型是 jboss-javaee6 Maven 原型,它也使用 Arquillian 在远程 JBoss 6 服务器中对代码进行单元测试。我执行了以下步骤:

添加 arquillian.xml

我在 src/test/resources 中添加了 Arquillian.xml:

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/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-remote" default="true">
       <property name="httpPort">8080</property>
   </container>   
</arquillian>

Shrinkwrap WebArchive 而不是 JavaArchive

使用 return Shrinkwrap。 create(WebArchive.class, "test.war") 而不是 JavaArchive.class 创建了该方法可用的 addAsWebInfResource() 方法,我可以在其中添加空的生成的 beans.xml

调整 pom.xml 以减少 CLASSPATH 长度

Eclipse 不断出现 javaw.exe 中断,并给出 CreateProcess error=87 消息。这是由于 CLASSPATH 对于控制台命令来说太长造成的。由于依赖项jboss-as-client添加了无数的依赖项,我将其更改为jboss-as-profileservice-client,它工作正常并且依赖项少得多。

另一件重要的事情是在 src/test/resources 目录中有一个 jndi.properties 文件,如 Arquillian 文档中所述。但这里已经是这种情况了。我猜 arquillian.xml 造成了差异 - 该文件从未在文档中提及,只是在原型中看到它。

这是我用于远程 JBoss 测试的 Maven 配置文件:

<profile>
  <id>jbossas-remote-6</id>
  <dependencies>
     <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-jbossas-remote-6</artifactId>
        <version>1.0.0.Alpha5</version>            
     </dependency>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>2.0.0.Final</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency> 
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-profileservice-client</artifactId>
        <version>6.0.0.Final</version>
        <type>pom</type>            
    </dependency>
  </dependencies>
<build>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>
</build>

我希望我的回答对某人有用。 :)

There are various things I did to make this work. My role model was the jboss-javaee6 Maven archetype, which is also using Arquillian for unit testing the code in a remote JBoss 6 server. I did the following steps:

Add arquillian.xml

I added the Arquillian.xml in src/test/resources:

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/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-remote" default="true">
       <property name="httpPort">8080</property>
   </container>   
</arquillian>

Shrinkwrap a WebArchive instead of JavaArchive

Using return Shrinkwrap.create( WebArchive.class, "test.war") instead of the JavaArchive.class made the method addAsWebInfResource() method available, where I could add the empty generated beans.xml.

Adjust pom.xml to reduce CLASSPATH length

Eclipse was constantly breaking with javaw.exe giving a CreateProcess error=87 message. This was caused by the CLASSPATH being too long for the console command. Since the dependency jboss-as-client added Bazillions of dependencies, I changed it to jboss-as-profileservice-client which works fine and has a lot less dependencies.

Another important thing is to have a jndi.properties file in the src/test/resources directory, as stated in the Arquillian docs. But that was already the case here. I guess the arquillian.xml made the difference - this file was never mentioned in the docs, just saw it in the archetype.

This is my Maven profile for remote JBoss testing:

<profile>
  <id>jbossas-remote-6</id>
  <dependencies>
     <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-jbossas-remote-6</artifactId>
        <version>1.0.0.Alpha5</version>            
     </dependency>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>2.0.0.Final</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency> 
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-profileservice-client</artifactId>
        <version>6.0.0.Final</version>
        <type>pom</type>            
    </dependency>
  </dependencies>
<build>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>
</build>

I hope my answer will be useful to somebody. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文