Maven 未在 class 后缀为 "Tester" 的文件中进行 运行 测试

Maven not running test in class files suffixed with "Tester"

mvn clean installmvn test 命令将 运行 对名为 SomethingTest.java 的文件进行所有测试,但不会 运行 对名为 [=] 的文件进行测试16=]

根据 docs for the maven surefire plugin 它应该 运行 测试默认匹配 **/Test*.java 模式,我是否缺少让 maven 识别遵循此模式的测试的步骤?

您链接到的文档说:

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

  • "**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
  • "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
  • "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

您的 class 与以下任何模式都不匹配:

  • 测试未启动
  • 测试未结束
  • 不以TestCase结束

然后医生说:

If the test classes do not follow any of these naming conventions, then configure Surefire Plugin and specify the tests you want to include.

几行之后,有说明和示例说明如何指定包含模式。

An include/exclude pattern can be an ant-style path expression, but regular expressions are also supported through this syntax:

[...]

意识到我实际上需要 运行 按照 **/*Test*.java 模式进行测试

我通过将以下内容添加到我的 pom.xml

<project>
    [...]
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test*.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    [...]
</project>