Maven 自动跳过测试

标签 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 Artifact 被正确复制到目标目录并跳过测试。 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{
        //...
    }

}

最佳答案

调试输出显示:

[DEBUG]   (s) skip = true

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

修复是添加

<skip>false</skip>

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

-Dmaven.test.skip=false

到你的命令行。

Reference

关于Maven 自动跳过测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17547931/

相关文章:

html - 使 TestNG Reporter 输出出现在 Gradle HTML 测试报告中

mysql - 通过 EC2 Jenkins 的 RDS MySql 上的连接过多错误

java - SNAPSHOT 和 RELEASE 版本未在 Maven 本地存储库中获得更新

java - 如何从 Intellij Maven 项目中永久删除模块?

testing - 实验室环境中的编码 UI 测试

java - TestNG预期异常处理: Have my cake as well as eat it?

java - 编译 Maven 项目的默认 Vaadin 小部件

javascript - 使用 npm run protractor 配置文件收到错误消息,该文件之前运行良好

html - 如何使用 capybara 在 HTML 文件中的两个表单之一中填写字段?

java - Spring Security 中用于身份验证的模拟对象