【问题标题】:Unable to Import From main Java Directory Into test Directory (IntelliJ)无法从主 Java 目录导入测试目录 (IntelliJ)
【发布时间】:2018-06-30 17:30:15
【问题描述】:

在我尝试将AssertJ 库添加到我的项目进行测试后,我的项目中的一些配置发生了更改,我无法将任何类从我的 ma​​in 包导入到我的 JUnit test 包。

我的主类按预期运行,但我无法运行任何需要主包中的类的测试。

我尝试了以下方法:

  • 删除 AssertJ 导入
  • 重建项目
  • 刷新所有 Gradle 项目
  • 使 IntelliJ 缓存无效并从设置重新启动
  • 在本地删除项目并从 GitHub 重新下载
  • 删除测试目录并重新添加

查看另一个正在运行的项目,这似乎是我的 build.gradle 文件

的问题

group 'carpecoin'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.2.41'
    ext.junitJupiterVersion  = '5.0.3'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    testImplementation group: 'junit', name: 'junit', version: '4.12'
    // JUnit Jupiter API and TestEngine implementation
    testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
    // To avoid compiler warnings about @API annotations in JUnit code
    testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
    implementation 'com.google.firebase:firebase-admin:6.0.0'
    implementation 'com.google.firebase:firebase-database:15.0.0'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

【问题讨论】:

    标签: java android firebase intellij-idea kotlin


    【解决方案1】:

    build.gradle 文件中的以下行失败导致上述问题。

    implementation 'com.google.firebase:firebase-database:15.0.0'

    我将 Firebase 更新为以下内容,现在在运行测试时仍然会导致问题。它似乎在生产中运行良好:

    implementation 'com.google.firebase:firebase-core:16.0.1'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-24
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 2022-06-14
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多