【问题标题】:Arquillian Tests not executed未执行 Arquillian 测试
【发布时间】:2015-11-11 00:18:30
【问题描述】:

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

|- 父级(包装 pom)
|-- ejb 模块
|-- 战争模块
|-- 耳模块

构建顺序是先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-Module 和

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

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

【问题讨论】:

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


    【解决方案1】:

    public class AccountRestITpublic class AccountEntityFacadeTest

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

    【讨论】:

    • 这使我能够为 wildfly-quickstart-24.0.1.Final/kitchenskink 运行 arquillian 测试,它带有一个名为 MemberRegistrationIT 的类。只需将其重命名为 MemberRegistrationTest 即可解决我的问题。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2022-01-02
    • 2015-09-20
    • 2015-03-17
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多