Arquillian测试未执行

时间:2015-08-18 07:20:44

标签: java maven java-ee testing jboss-arquillian

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

| - 父母(包装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。没有关于输出的其他信息。我刚收到消息"没有执行任何测试"。战争模块取决于Ejb模块和

父-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-Module 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-Module的测试类(执行)

@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-Module的测试类(未执行)

@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-module测试。

1 个答案:

答案 0 :(得分:7)

public class AccountRestITpublic class AccountEntityFacadeTest

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