【问题标题】:How to run all the test files and trigger test using maven-surefire plugin如何使用 maven-surefire 插件运行所有测试文件并触发测试
【发布时间】:2014-11-08 08:05:34
【问题描述】:

我正在用 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. 当我运行命令“mvn clean install test”时,surefire 会运行,但它会跳过所有测试文件。

  3. 当我运行命令“mvn clean install -Dtest=com.example.AllTests.java -DfailIfNoTests=false”时,java 文件运行成功

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

谁能帮助我了解如何使用 Maven 实现这一目标。

提前感谢您的帮助。

【问题讨论】:

  • 在第 1 点,你有 com.example.AllTests.java,在第 3 点,它是单数 com.example.AllTest.java
  • 哦,请忽略...让我编辑它

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


【解决方案1】:

不要包含src/test/java/,而是使用&lt;include&gt;com/example/AllTests.java&lt;/include&gt;。 顺便说一句,如果是surefire-plugin,则无需指定执行块,因为它已经作为构建生命周期的一部分被调用(除非您有一个罕见的设置)。配置块到这里就够了。

【讨论】:

  • 谢谢 Rob,我会试试这个。
猜你喜欢
  • 2021-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多