Maven自动跳过测试 [英] Maven is automatically skipping tests

查看:119
本文介绍了Maven自动跳过测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Maven为何跳过所有测试?我的pom.xml配置文件很少,并且我无法通过它们进行测试.我的个人资料之一

How come that Maven is skipping all of my tests by default?I have a pom.xml with few profiles and I am not able to run my tests through neither of them. One of my profiles looks like

<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进行实际测试,但是不确定该问题是否重要.

If I run mvn verify -Pjsf-test then the project is compiled, jsf-app artifact is correctly copied into target directory and tests are skipped. mvn verify -Dtest=TestCalculator has the same result. I am using Arquillian and TestNG to perform the actual tests but I am not sure if it matters for this question.

编辑

在调试中运行将提供(相关部分)

Running in debug will give (the relevant part)

[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.

我最简单的测试是这样的

My simplest test looks like this

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

}

推荐答案

调试输出显示以下内容:

The debug output shows this:

[DEBUG]   (s) skip = true

不仅跳过运行测试,还将跳过编译测试.如果您好奇的话,请检查父POM(由该POM直接引用,也可以由Arquillian引入的任何公司POM或超级POM)来查看此标志的设置位置.

which not only skips running the tests, it will also skip compiling them. Check the parent POM (directly referenced by this POM, also any corporate POMs or super POMs introduced by Arquillian) to see where this flag is being set, if you're curious.

解决方法是添加

<skip>false</skip>

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

to the surefire plugin config in this module, or add

-Dmaven.test.skip=false

到您的命令行.

参考

这篇关于Maven自动跳过测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆