如何使用maven-surefire插件运行所有测试文件并触发测试

时间:2014-09-14 19:28:53

标签: maven maven-plugin maven-surefire-plugin

我正在maven建立一个项目 我有一些测试文件,我希望它们在我编译或打包项目时执行

这是我到目前为止所尝试的内容:

  1. pom.xml看起来像这样

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <executions>
                <execution>
                    <id>test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <includes>
                            <include>src/test/java/**/com.example.AllTests.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <skip>false</skip>
            </configuration>
        </plugin>
    
  2. 当我运行命令&#34; mvn clean install test&#34;时,surefire会运行,但它会跳过所有测试文件。

  3. 当我运行命令&#34; mvn clean install -Dtest = com.example.AllTests.java -DfailIfNoTests = false&#34;然后java文件成功运行

  4. 在一个更大更复杂的项目中,我不想运行多个命令。我想只运行一个命令,我希望maven运行测试文件,生成测试报告并继续运行应用程序。

    任何人都可以帮助我了解如何通过Maven实现这一目标。

    感谢您提前提供任何帮助。

1 个答案:

答案 0 :(得分:1)

请勿包含src/test/java/,但请使用<include>com/example/AllTests.java</include>。 顺便说一句,在surefire-plugin的情况下,没有必要指定执行块,因为它已经被称为构建生命周期的一部分(除非你有一个罕见的设置)。配置块就足够了。

相关问题