gpt4 book ai didi

java - Maven 未在后缀为 "Tester"的类文件中运行测试

转载 作者:行者123 更新时间:2023-12-01 07:54:51 26 4
gpt4 key购买 nike

mvn clean installmvn test 命令将在名为 SomethingTest.java 的文件上运行所有测试,但不会在名为 SomethingTester.java

的文件

根据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:

[...]

关于java - Maven 未在后缀为 "Tester"的类文件中运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com