【问题标题】:IDEA, Hamcrest and static importsIDEA、Hamcrest 和静态导入
【发布时间】:2012-10-30 23:07:11
【问题描述】:

我的 maven 项目包括

186         <dependency>
187             <groupId>org.hamcrest</groupId>
188             <artifactId>hamcrest-all</artifactId>
189             <version>1.3</version>
190         </dependency>

当我输入assertThat ..

我想让 IDEA 弄清楚需要以下内容

import static org.hamcrest.MatcherAssert.assertThat;

相反,我得到了这个。

如何纠正?如何让 IDEA 执行静态导入?

【问题讨论】:

  • 顺便说一句:您可能希望在 Hamcrest 和其他测试库的依赖项声明中包含 &lt;scope&gt;test&lt;/scope&gt;

标签: java intellij-idea hamcrest


【解决方案1】:

打开括号,你会得到一个静态导入方法的提示。在添加括号之前,IntelliJ 不会理解这是您尝试引用的方法。

换句话说,输入assertThat(,然后输入ALT-ENTER

【讨论】:

  • 没问题。 equalTo() 和其他匹配器显然也是如此。
猜你喜欢
  • 2017-02-27
  • 2013-02-26
  • 2019-05-05
  • 2015-04-13
  • 2017-12-07
  • 2016-05-24
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
相关资源
最近更新 更多