未找到使用 Bazel 目标的 Kotlin JUnit5 测试

Kotlin JUnit5 tests using Bazel target not found

我在 Kotlin 中有一个 Bazel 项目,我正在尝试 运行 使用 JUnit 5 进行单元测试。 这是我的目标:

kt_jvm_library(
    name = "lib",
    srcs = glob(["src/main/kotlin/**/*.kt"]),
)

kt_jvm_test(
    name = "tests",
    main_class = "org.junit.platform.console.ConsoleLauncher",
    args = [
        "--select-package=com.acme",
    ],
    srcs = glob(["src/test/kotlin/**/*.kt"]),
    deps = [
        ":lib",
        "@maven//:org_junit_jupiter_junit_jupiter_api",
        "@maven//:org_junit_jupiter_junit_jupiter_engine",
        "@maven//:org_junit_jupiter_junit_jupiter_params",
        "@maven//:org_junit_platform_junit_platform_console",
    ],
)

当我 运行 bazel run //:tests 时,我得到这个输出:

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

╷
└─ JUnit Jupiter ✔

Test run finished after 43 ms
[         1 containers found      ]
[         0 containers skipped    ]
[         1 containers started    ]
[         0 containers aborted    ]
[         1 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]

如您所见,未找到任何测试。我的配置有什么问题?

我发现了错误。我的测试 类' 名称不匹配 *Test.kt 模式,而是 *Should.kt。当我更改他们的名字以匹配 *Test.kt 时,发现测试一切正常。

我会接受这个答案是正确的,但是,如果有人知道我如何保持我的测试 类 命名风格并使其正常工作,我们将不胜感激。

根据JUnit 5 Document,ConsoleLauncher 有以下选项,

  -n, --include-classname=PATTERN
                             Provide a regular expression to include only classes whose
                               fully qualified names match. To avoid loading classes
                               unnecessarily, the default pattern only includes class
                               names that begin with "Test" or end with "Test" or
                               "Tests". When this option is repeated, all patterns will
                               be combined using OR semantics. Default: [^(Test.*|.+[.$]
                               Test.*|.*Tests?)$]
  -N, --exclude-classname=PATTERN
                             Provide a regular expression to exclude those classes whose
                               fully qualified names match. When this option is repeated,
                               all patterns will be combined using OR semantics.
      --include-package=PKG  Provide a package to be included in the test run. This
                               option can be repeated.
      --exclude-package=PKG  Provide a package to be excluded from the test run. This
                               option can be repeated.
  -t, --include-tag=TAG      Provide a tag or tag expression to include only tests whose
                               tags match. When this option is repeated, all patterns
                               will be combined using OR semantics.
  -T, --exclude-tag=TAG      Provide a tag or tag expression to exclude those tests whose
                               tags match. When this option is repeated, all patterns
                               will be combined using OR semantics.
  -e, --include-engine=ID    Provide the ID of an engine to be included in the test run.
                               This option can be repeated.
  -E, --exclude-engine=ID    Provide the ID of an engine to be excluded from the test
                               run. This option can be repeated.