为什么黄瓜会找到 "runTest.java" 到 运行 测试?

Why cucumber will find the "runTest.java" to run tests?

我在写一些cucumber测试的时候,从一些文档中发现我需要在"src/test/java/somepackage"下创建一个"runTest.java"文件,里面配置cucumber的内容,比如:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"})
public class runTest {
}

我发现 class 名称 "runTest" 很有趣,因为如果我将它重命名为任何其他名称,mvn test 将找不到它。

我从 junit 站点搜索了名称转换,但没有找到任何相关文档。只是想知道更多关于它的信息。

我认为惯例是:

  • Test*.java
  • *Test.java
  • *TestCase.java

这不是 JUnit 约定,而是定义它的 Maven surefire 插件:https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

参考:https://scompoprojects.wordpress.com/2016/02/03/junit-test-class-names-are-important-with-maven/