31

为什么 Maven 默认会跳过我的所有测试?我有pom.xml几个配置文件,我无法通过它们运行我的测试。我的个人资料之一看起来像

<profile>
        <id>jsf-test</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.as</groupId>
                <artifactId>jboss-as-arquillian-container-remote</artifactId>
                <version>${jboss.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.jsf.tests</groupId>
                <artifactId>jsf-app</artifactId>
                <version>${jsf-app.version}</version>
                <type>war</type>
            </dependency>
        </dependencies>
        <build>
            <plugins>                
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <id>copy-jsf-app</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>com.jsf.tests</groupId>
                                        <artifactId>jsf-app</artifactId>
                                        <version>${jsf-app.version}</version>
                                        <type>war</type>
                                        <destFileName>jsfapp.war</destFileName>
                                        <outputDirectory>target</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire.version}</version>
                    <configuration>
                        <skipTests>false</skipTests> <!-- desperate trial -->
                        <properties>
                            <property>
                                <name>listener</name>
                                <value>${testng.listeners}</value>
                            </property>
                        </properties>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

如果我运行mvn verify -Pjsf-test,则编译项目,将jsf-app工件正确复制到目标目录并跳过测试。mvn verify -Dtest=TestCalculator有相同的结果。我正在使用ArquillianTestNG执行实际测试,但我不确定这对这个问题是否重要。

编辑

在调试中运行将给出(相关部分)

[DEBUG]   (s) reportFormat = brief
[DEBUG]   (s) reportsDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-    test/target/surefire-reports
[DEBUG]   (f) reuseForks = true
[DEBUG]   (s) runOrder = filesystem
[DEBUG]   (s) skip = true
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) systemPropertyVariables = {jsfPortlet=true}
[DEBUG]   (s) testClassesDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (s) testNGArtifactName = org.testng:testng
[DEBUG]   (s) testSourceDirectory = /home/pmensik/Work/workspace/epp-test    /cdi-arquillian-test/src/test/java
[DEBUG]   (s) trimStackTrace = true
[DEBUG]   (s) useFile = true
[DEBUG]   (s) useManifestOnlyJar = true
[DEBUG]   (s) useSystemClassLoader = true
[DEBUG]   (s) useUnlimitedThreads = false
[DEBUG]   (s) workingDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test
[DEBUG]   (s) project = MavenProject: org.jboss.gatein.test:cdi-portlet-test:6.1-ER01 @ /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test/pom.xml
[DEBUG]   (s) session = org.apache.maven.execution.MavenSession@3c3483ec
[DEBUG] -- end configuration --
[INFO] Tests are skipped.

我最简单的测试看起来像这样

public class Test {

    @Drone
    protected WebDriver driver;

    @Deployment(testable = false)
    public static WebArchive createTestArchive() {
        return ShrinkWrap.createFromZipFile(WebArchive.class, new File("target/CDIPortlet.war"));
    }

    @Test
    public void testCase{
        //...
    }

}
4

1 回答 1

38

调试输出显示:

[DEBUG]   (s) skip = true

它不仅会跳过运行测试,还会跳过编译它们。如果您好奇,请检查父 POM(此 POM 直接引用,以及 Arquillian 引入的任何公司 POM 或超级 POM)以查看此标志的设置位置。

解决方法是添加

<skip>false</skip>

到这个模块中的surefire插件配置,或者添加

-Dmaven.test.skip=false

到你的命令行。

参考

于 2013-07-10T13:52:32.177 回答