【问题标题】:IntelliJ does not use JUnit import in Integration Tests (Gradle project)IntelliJ 在集成测试(Gradle 项目)中不使用 JUnit 导入
【发布时间】:2016-06-04 00:23:34
【问题描述】:

我有一个预定义的项目结构,其中包含有效的 Gradle 依赖管理和以下 Gradle JUnit 解析:

dependencies {
    [...]
    testCompile "junit:junit:${versions.junit}"
    integrationTestCompile "junit:junit:${versions.junit}"
}

项目结构是

<project>
    <module>
        src
            integration-test
            main
            test

现在,虽然 test 类在 IntelliJ 中编译得很好,但 integrationTest 类仍然不能。在...

import org.junit.Assert;

...有人告诉我:“无法解析符号‘断言’。

作为一个 IntelliJ(以及 Gradle)新手,我对处理这个问题感到很困惑。虽然this answer 告诉我我可以将testCompileintegrationTestCompile 都映射到IDEA 的test 范围(没有描述如何),that answer 指的是Gradle IdeaModule 文档,但这根本不是很解释这点。

那么,什么是正确或最好的方法,具体需要做什么?

【问题讨论】:

  • 这个问题只发生在 IntelliJ 上,还是在 IntelliJ 之外运行集成测试时出错?
  • @EricWendelin 感谢合作!请参阅下面的答案。有什么悬而未决的问题吗?

标签: intellij-idea gradle junit dependencies resolve


【解决方案1】:

问题同时通过以下方式解决:

A) 在 build.gradle 中输入:

configurations {
    provided
    testCompile.extendsFrom provided
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
    [...]
}

B)Gradle Refresh

【讨论】:

    猜你喜欢
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    • 2016-06-09
    相关资源
    最近更新 更多