寻求解决this不知何故 that ,我试图创建包来分割 main
和 test
类,然后使用带有添加模块的编译器来执行单元测试。不是一个很好的方式同意,但现在只是一个假设的结构。
随着我的深入,很少有 Unresolved 问题是:-
- 将基于 JDK9 的模块添加到项目中。
- 使用 IntelliJ 的快捷方式将 JUnit5 添加到类路径中。 (库文件夹)[
junit-jupiter-api-5.0.0.jar
]
问。请注意,它会将 opentest4j-1.0.0.jar
带到 lib/文件夹中。为什么会这样,另一个 jar 是做什么用的?
添加类并相应地生成一些测试方法。
编译 sample project (分享只是为了画一下使用中的目录结构)使用命令
javac --module-path lib -d "target" $(find src -name "*.java")
结果警告为 -
warning: unknown enum constant Status.STABLE reason: class file for org.apiguardian.api.API$Status not found warning: unknown enum constant Status.STABLE 2 warnings
注意:-
我发现 junit-jupiter
的用法很可疑,因为如果我使用 JUnit 注释掉代码并执行相同的命令,事情似乎工作正常。
库/工具 如果这可能很重要,则使用:-
junit-jupiter-api-5.0.0
和- Java 版本
“9”(build 9+181)
- IntelliJ
2017.2.5
问。这种警告的可能原因是什么?此外,我无法在我的项目中和项目类之外找到 API.Status
。
最佳答案
编译警告可以忽略。此外,从 5.1.0
版本(目前正在开发中)开始,它将不再出现。这一切都在Release Notes中解释。 :
In 5.0.1, all artifacts were changed to have an optional instead of a mandatory dependency on the @API Guardian JAR in their published Maven POMs. However, although the Java compiler should ignore missing annotation types, a lot of users have reported that compiling tests without having the @API Guardian JAR on the classpath results in warnings emitted by
javac
that look like this:warning: unknown enum constant Status.STABLE reason: class file for org.apiguardian.api.API$Status not found
To avoid confusion, the JUnit team has decided to make the dependency to the @API Guardian JAR mandatory again.
另请参阅:
关于java - 警告 : unknown enum constant Status. 稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46702273/