Arquillian 测试未执行

Arquillian Tests not executed

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

|- parent (packaging pom)
|-- ejb 模块
|-- war-模块
|-- 耳机模块

构建顺序首先是 ejb-module,然后是 war-module,然后是 ear-module。该项目依赖于 arquillian 进行测试。 ejb-module 和 war-module 都包含一个测试。当我运行 "mvn clean test -Parq-wildfly-managed"(配置文件是激活测试)执行了ejb-module的测试,但是没有执行war-module的测试并且没有surefire-report in目标文件夹。没有关于输出的附加信息。我刚收到消息 "No tests were executed"。 War-Module 依赖于 Ejb-Module 和

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-模块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 模块的测试 class(已执行)

@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));
    }
}

测试 class of 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);
}

我已经尝试删除默认情况下的配置文件和 运行 测试,但仍然无法识别 war 模块测试。

public class AccountRestIT 对比 public class AccountEntityFacadeTest

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