Maven正在自动跳过测试

时间:2013-07-09 12:15:35

标签: maven testing testng jboss-arquillian

为什么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{
        //...
    }

}

1 个答案:

答案 0 :(得分:27)

调试输出显示:

[DEBUG]   (s) skip = true

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

修复是添加

<skip>false</skip>

到此模块中的surefire插件配置,或添加

-Dmaven.test.skip=false

到您的命令行。

Reference