我有关于 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 任务”的更多最新详细信息可以在此处找到:https://ant.apache.org/manual/Tasks/junitlauncher.html
关于java - junit 5 编译为模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60348320/