Arquillian测试未执行 [英] Arquillian Tests not executed

查看:289
本文介绍了Arquillian测试未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块项目,用maven组织和构建。它由一个war-module,一个ejb-module和一个ear-module组成。他们拥有相同的父项目(用于依赖管理)。结构如下:

I have a multi module project, organised and built with maven. It consists of a war-module, an ejb-module and an ear-module. They alle have the same parent project (for dependencymanagement). Structure is like:

| - 父(包装pom)

| - ejb-module

| - war -module

| - ear-module

|- parent (packaging pom)
|-- ejb-module
|-- war-module
|-- ear-module

建立顺序是第一个ejb-module然后是war-module而不是ear-module。该项目依赖于arquillian进行测试。 ejb-module和war-module都包含一个测试。当我运行mvn clean test -Parq-wildfly-managed(配置文件是激活测试)时,执行ejb-module的测试,但是war-module的测试没有执行,目标中没有surefire-report夹。输出没有其他信息。我刚收到消息没有执行任何测试。 War-Module取决于Ejb模块和

Built order is first ejb-module then war-module than ear-module. The project depends on arquillian for testing. Both ejb-module and war-module contain a test. When I run "mvn clean test -Parq-wildfly-managed" (profile is to activate testing) the test of ejb-module is executed, but the test of war-module is not executed and there is no surefire-report in the target folder. There is no additional information on the output. I just get the message "No tests were executed". The War-Module depends on the Ejb-Module and

Parent-Pom

<modelVersion>4.0.0</modelVersion>
<groupId>de.wilhelm</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>ejb-module</module>
    <module>web-module</module>
    <module>ear-module</module>
</modules>

<properties>
    <!-- Explicitly declaring the source encoding eliminates the following 
    message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
    resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

    <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
    <version.jboss.bom>8.2.1.Final</version.jboss.bom>
    <version.wildfly>9.0.0.Alpha1</version.wildfly>


    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.ear.plugin>2.10</version.ear.plugin>
    <version.ejb.plugin>2.3</version.ejb.plugin>
    <version.surefire.plugin>2.16</version.surefire.plugin>
    <version.war.plugin>2.5</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
</properties>

<dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.2-b01</version>
            <scope>provided</scope>
        </dependency>

        <!-- Define the version of the EJB jar so that we don't need 
        to repeat ourselves in every module -->
        <dependency>
            <groupId>de.wilhelm</groupId>
            <artifactId>ejb-module</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
            <scope>compile</scope>
        </dependency>

        <!-- Define the version of the WAR so that we don't need to repeat 
        ourselves in every module -->
        <dependency>
            <groupId>de.wilhelm</groupId>
            <artifactId>web-module</artifactId>
            <version>${project.version}</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>

        <!-- JBoss distributes a complete set of Java EE 7 APIs including
        a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or 
        a collection) of artifacts. We use this here so that we always get the correct 
        versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack
        (you can read this as the JBoss stack of the Java EE 7 APIs, with some extras
        tools for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
        stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
        from the Hibernate family of projects) -->
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-with-tools</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <!-- The WildFly plugin deploys your ear to a local JBoss
            AS container -->
            <!-- Due to Maven's lack of intelligence with EARs we need 
            to configure the wildfly maven plugin to skip deployment for all modules.
            We then enable it specifically in the ear module. -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
                <inherited>true</inherited>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

EJB模块POM

 <parent>
    <artifactId>parent</artifactId>
    <groupId>de.wilhelm</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>ejb-module</artifactId>
<packaging>ejb</packaging>

<name>EJB Module</name>

<dependencies>

    <!-- Declare the APIs we depend on and need for compilation. All of 
    them are provided by JBoss WildFly -->

    <!-- Import the EJB API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JPA API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- JSR-303 (Bean Validation) Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
    </dependency>


    <!-- Test scope dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Optional, but highly recommended -->
    <!-- Arquillian allows you to test enterprise code such as EJBs and 
    Transactional(JTA) JPA from JUnit/TestNG -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>               
    </dependency>

</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${version.ejb.plugin}</version>
            <configuration>
                <!-- Tell Maven we are using EJB 3.1 -->
                <ejbVersion>3.1</ejbVersion>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
    <!--             The default profile skips all tests, though you can tune it 
        to run just unit tests based on a custom pattern 
         Seperate profiles are provided for running all tests, including 
        Arquillian tests that execute in the specified container -->
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.surefire.plugin}</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
    <!--             An optional Arquillian testing profile that executes tests 
        in your WildFly instance 
         This profile will start a new WildFly instance, and execute
        the test, shutting it down when done 
         Run with: mvn clean test -Parq-wildfly-managed -->
        <id>arq-wildfly-managed</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

    <profile>
    <!--             An optional Arquillian testing profile that executes tests 
        in a remote WildFly instance 
         Run with: mvn clean test -Parq-wildfly-remote -->
        <id>arq-wildfly-remote</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

</profiles>

WAR-Module POM

<parent>
    <artifactId>parent</artifactId>
    <groupId>de.wilhelm</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>web-module</artifactId>
<packaging>war</packaging>

<name>WAR Module</name>

<dependencies>

    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Dependency on the EJB module so we can use it's services if needed -->
    <dependency>
        <groupId>de.wilhelm</groupId>
        <artifactId>ejb-module</artifactId>
        <type>ejb</type>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JSF API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JPA API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- JSR-303 (Bean Validation) Implementation -->
    <!-- Provides portable constraints such as @Email -->
    <!-- Hibernate Validator is shipped in JBoss WildFly -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!--Test scope dependencies--> 
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <!--         Optional, but highly recommended 
     Arquillian allows you to test enterprise code such as EJBs and 
    Transactional(JTA) JPA from JUnit/TestNG -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>               
    </dependency>

</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <!--             The default profile skips all tests, though you can tune it 
        to run just unit tests based on a custom pattern 
         Seperate profiles are provided for running all tests, including 
        Arquillian tests that execute in the specified container -->
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.surefire.plugin}</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <!--             An optional Arquillian testing profile that executes tests 
       in your WildFly instance 
        This profile will start a new WildFly instance, and execute
       the test, shutting it down when done 
        Run with: mvn clean test -Parq-wildfly-managed -->
        <id>arq-wildfly-managed</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

    <profile>
        <!--             An optional Arquillian testing profile that executes tests 
       in a remote WildFly instance 
        Run with: mvn clean test -Parq-wildfly-remote -->
        <id>arq-wildfly-remote</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

</profiles>

EJB模块的测试类(执行)

@RunWith(Arquillian.class)
public class AccountEntityFacadeTest {
@Deployment
public static WebArchive createDeployment() {
    return ShrinkWrap.create(WebArchive.class)
            .addClasses(AccountEntity.class, AccountEntityFacade.class, AbstractFacade.class, AccountEntityBuilder.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") // activates CDI
            .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource("test-ds.xml", "test-ds.xml");
}

@PersistenceContext(unitName = "primary")
public EntityManager em;

@Inject
AccountEntityFacade userFacade;

@Inject
AccountEntityBuilder accountBuilder;

@Before
public void prepare() throws Exception {
    clearData();
}

private void clearData() throws Exception{
}

@After
public void clear() throws Exception {
}

@Test
public void crudOperations() {
      // valid create operations
    AccountEntity a = accountBuilder.buildMemberAccount("a@a", "a", "a");
    AccountEntity b = accountBuilder.buildMemberAccount("b@b", "b", "b");
    userFacade.create(a);
    userFacade.create(b);
    AccountEntity aLoaded = userFacade.find(a.getEmail());
    assert(aLoaded.equals(a));
    }
}

WAR模块的测试类(不是执行)

@RunWith(Arquillian.class)
public class AccountRestIT {

@Deployment
public static WebArchive createDeployment() {
    return ShrinkWrap.create(WebArchive.class)
            .addClasses(AccountRest.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") // activates CDI
            .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource("test-ds.xml", "test-ds.xml");
}

@Inject
AccountRest accountRest;

@Before
public void prepare() throws Exception {
}

@After
public void clear() throws Exception {
}

@Test
public void testRestApi() {
    Assert.assertTrue(true);
}

我已经尝试删除配置文件并在默认情况下运行测试但是战争 - 模块测试仍然无法识别。

I already tried to remove the profiles and run tests on default but the war-module tests were still not recognized.

推荐答案

公共类AccountRestIT 公开class AccountEntityFacadeTest

surefire-maven-plugin 无法识别以<结尾的测试code> * IT 。您应该将其名称更改为 * Test 或使用其他技术。有关参考,请参阅答案。

surefire-maven-plugin does not recognize tests that ends with *IT. You should change it's name to *Test or use other technique. For reference see this answer.

这篇关于Arquillian测试未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆