【问题标题】:IDE does not recognize AssumptionsIDE 无法识别假设
【发布时间】:2020-06-02 04:04:19
【问题描述】:

我正在使用 Junit5,而我的 IDE (IntelijIdea) 无法识别 Assumptions。我实际上不知道为什么,但可能对 Maven 有一些依赖,我没有连接到项目中。下面我将向您展示我的代码示例。

这是我的假设导入。

import org.junit.jupiter.api.Assumptions;

这是错误的代码(我无法编译它,编译器不知道什么是假设True())

@Test
@EnabledOnOs(OS.MAC)
void testInsertion() {
    assumeTrue(isServerUp); //That place is crashing
    assertThrows(NullPointerException.class, () -> Connection.insertTheInstance(person),
            "");

如果您熟悉此案例,请分享您的知识)非常感谢!

【问题讨论】:

  • JUnit 5 由几个模块组成,并且假设是 junit-jupiter-api 库的一部分,因此您需要在 pom 文件中使用此依赖项,例如最新稳定版是5.6.2
  • 你能用 Maven 从命令行编译项目吗?
  • 不,我试过了)

标签: java maven intellij-idea junit junit-jupiter


【解决方案1】:

这可能是一个导入问题。试试:

  <dependency>
     <groupId>org.junit.jupiter</groupId>
     <artifactId>junit-jupiter-api</artifactId>
     <version>5.6.2</version>
     <scope>test</scope>
  </dependency> 
  • 检查maven导入是否正常
  • 在 intellij 中关闭您的项目
  • 删除 HOME 目录中的 .m2 文件夹(windows 中的 user/yourusername,linux 中的 /home)
  • 在项目的终端中执行:mvn dependency:purge-local-repository clean。
  • 再次打开您的项目

如果还不行,试试junit 4.12。它也有假设。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-02
    • 2020-04-05
    • 2017-12-26
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多