junit 5 编译为模块

junit 5 compile as module

我有一个关于 junit.jupiter 的问题。将测试编译为模块有用吗?类似的东西?

module usecases {
  requires org.junit.jupiter.api;
}

当我尝试使用 ant 进行编译时,出现以下错误消息:

[javac] error: module not found: org.opentest4j
[javac] error: module not found: org.apiguardian.api

我不明白,因为在类路径中它可以毫无问题地编译,但在模块路径中却不行?

两个模块以及 org.junit.platform.commons 都需要满足 org.junit.jupiter.api 的声明。请参阅模块描述符的此片段:

/**
 * Defines JUnit Jupiter API for writing tests.
 */
module org.junit.jupiter.api {
    requires transitive org.apiguardian.api;
    requires transitive org.junit.platform.commons;
    requires transitive org.opentest4j;

    exports org.junit.jupiter.api;
...
}

这就是为什么您必须配置构建工具以至少提供这三个模块。

IIRC,Ant 的默认 "JUnit 5" 集成使用非模块化 junit-platform-console-standalone 工件。它的 JAR 确实包含所有必需的正常 类 但没有 module-info.class 文件。因此,在类路径上编译和 运行 开箱即用。

可以在此处找到有关使用 "JUnitLauncher Task" 的更多最新详细信息:https://ant.apache.org/manual/Tasks/junitlauncher.html