【问题标题】:unresolved supertypes: org.junit.rules.ExternalResource when using MockWebServer with Junit 5未解决的超类型:将 MockWebServer 与 Junit 5 一起使用时的 org.junit.rules.ExternalResource
【发布时间】:2020-04-07 21:12:20
【问题描述】:

我正在使用来自 okhttp3 的 MockWebServer

dependencies {
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
    testImplementation "org.junit.jupiter:junit-jupiter-migration-support:5.0.0-M4"
    testImplementation "junit:junit:4.12"
    testImplementation "com.squareup.okhttp3:mockwebserver:4.2.1"
}

当我尝试使用此代码时:

    mockwebserver.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK))

我得到错误:

e:无法解析以下类的超类型。请确保您在类路径中具有所需的依赖项: 类 okhttp3.mockwebserver.MockWebServer,未解析的超类型:org.junit.rules.ExternalResource

我找到了this 的对话,但它无助于解决问题。

【问题讨论】:

    标签: android junit5 mockwebserver


    【解决方案1】:

    您使用了错误的人工制品。正确的在这里:https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-migrationsupport 它也有对应的5.5.2版本

    可能还有其他问题,但这是首先要解决的问题。

    【讨论】:

    • 谢谢。它不能解决问题,但这是错误的
    • 即使我的问题不同,我也会批准您的回答。当我写这个问题时,我简化了代码(这在真实的应用程序中非常复杂)。我以为我已经报告了所有重要的事情,但实际上我犯了一个错误:其中一个导入是使用mockImplementation 而不是testImplementationmock 前缀在那里是因为我有一种叫做mock 的风格。所以我在一个版本中导入了 migrationsupport 库,在另一个版本中导入了 mockwebserver 库。无论如何,您的答案是我所问问题的正确答案。
    猜你喜欢
    • 2021-12-08
    • 2017-11-09
    • 2017-09-02
    • 2018-07-10
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多