关于java:Arquillian测试未执行

Arquillian Tests not executed

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

| - 父母(包装pom)
| - ejb-module
| - war-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模块和

家长双响炮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<modelVersion>4.0.0</modelVersion>
<groupId>de.wilhelm</groupId>
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>
            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>
            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>
            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>
            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>
            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>
                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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
 <parent>
    parent</artifactId>
    <groupId>de.wilhelm</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

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>
        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>
        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>
        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>
        hibernate-validator</artifactId>
        <scope>provided</scope>
    </dependency>


    <!-- Test scope dependencies -->
    <dependency>
        <groupId>junit</groupId>
        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>
        arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

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

</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            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>
       
            true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    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>
                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>
                wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

</profiles>

WAR-Module POM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<parent>
    parent</artifactId>
    <groupId>de.wilhelm</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

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

<name>WAR Module</name>

<dependencies>

    <dependency>
        <groupId>javax.annotation</groupId>
        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>
        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>
        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>
        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>
        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>
        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>
        hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!--Test scope dependencies-->
    <dependency>
        <groupId>junit</groupId>
        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>
        arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

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

</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            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>
       
            true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    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>
                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>
                wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

</profiles>

EJB-Module的测试类(执行)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@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模块的测试类(未执行)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@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测试。


public class AccountRestITpublic class AccountEntityFacadeTest

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