【问题标题】:Maven is automatically skipping testsMaven 自动跳过测试
【发布时间】:2013-07-07 01:00:56
【问题描述】:

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

}

【问题讨论】:

  • 您确定您没有以某种方式使用-DskipTests 运行吗? mvn clean verifymvn clean install 有什么作用?
  • 尝试使用-X 运行以获取调试输出,然后查看surefire 插件的配置。我也会怀疑插件继承问题。是否在父 POM 中配置了 surefire 插件?
  • 你的测试是在哪里定义的?
  • @vikingsteve - 完全相同的结果
  • @user944849 - 查看我的编辑。是的,我继承自非常简单的 POM,在 pluginManagement 中只有一个 Surefire 插件的定义,跳过了配置,没有别的

标签: maven testing testng jboss-arquillian


【解决方案1】:

调试输出显示如下:

[DEBUG]   (s) skip = true

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

解决方法是添加

<skip>false</skip>

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

-Dmaven.test.skip=false

到你的命令行。

Reference

【讨论】:

  • true -- 测试已编译,但未运行。
  • true -- 甚至没有编译测试。
  • 这对我有用,但我不知道为什么会这样。由于我的 pom.xml 文件都没有将其设置为 false。
  • 我认为在 POM 中有 &lt;skip&gt;true&lt;/skip&gt; 时将 -Dmaven.test.skip=false 添加到命令中会被忽略。只是一个注释。在我将其更改为 &lt;skip&gt;false&lt;/skip&gt; 之前,它对我不起作用
  • @Nom1fan - 正确。如果该值已像这样硬编码,则无法再使用该属性中的值。如果您有权访问 POM,则可以删除硬编码并使用属性。
猜你喜欢
  • 2014-09-03
  • 2021-04-30
  • 1970-01-01
  • 2013-04-30
  • 2011-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多