无法在 IntelliJ 中使用 Snakeyaml 运行单元测试
我创建了一个 Java 组件,它使用 SnakeYaml 读取 YAML 文件。我使用的环境是带有 Maven 插件的 IntelliJ,我的项目是使用 Maven pom 文件构建的。当我运行 Maven 测试项目时,我的单元测试全部通过。但是,当我直接在 IntelliJ 中运行单元测试时,它们失败了。
具体来说,下面的调用 new Yaml(myConstructor) 会抛出异常:
Constructor myConstructor = new Constructor(....)
Yaml yaml = new Yaml(myConstructor)
具体异常是:
java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.(Lorg/yaml/snakeyaml/constructor/BaseConstructor;)V
有什么想法吗?
I have created a Java component which reads a YAML file using SnakeYaml. The environment I use is IntelliJ with a Maven plug-in and my project is built using a Maven pom file. When I run the Maven test project, my unit tests all pass. However, when I run the unit tests within IntelliJ directly, they fail.
Specifically, the call new Yaml(myConstructor) below is throwing an exception:
Constructor myConstructor = new Constructor(....)
Yaml yaml = new Yaml(myConstructor)
The specific exception is:
java.lang.NoSuchMethodError:
org.yaml.snakeyaml.Yaml.(Lorg/yaml/snakeyaml/constructor/BaseConstructor;)V
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发生这种情况是因为 TestNG 插件。对于 IntelliJ 和 Eclipse 来说这都是一个问题。
有两种方法可以轻松解决:
第二种方法是首选,因为 TestNG 依赖项将由您的构建工具管理(您使用构建工具吗?!)并且您有更多的灵活性。
This happens because of the TestNG plugin. It's an issue for both IntelliJ and Eclipse.
Easily solved in two ways:
The second way would be preferred because TestNG dependencies will be managed by your build tool (are you using a build tool, right ?!) and you have a lot more flexibility.
看看
file ->项目结构->工件。可能会有错误。只需单击“修复”按钮即可。还可以尝试从 Maven 配置重新创建 itellij 项目。通常,库范围会出现问题,例如
TEST/PROVIDED
。Take look at
file -> proj structure -> artifact
s. There can be error. Just click at "Fix" button. Also try recreate itellij project from maven configuration. Usually there is troubles with libraries scopes, likeTEST/PROVIDED
.以下内容对我有用
The below worked for me