java - 无法从主 Java 目录导入到测试目录 (IntelliJ)

标签 java android firebase intellij-idea kotlin

在我尝试添加 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"
}

enter image description here

最佳答案

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

实现“com.google.firebase:firebase-database:15.0.0”

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

实现“com.google.firebase:firebase-core:16.0.1”

关于java - 无法从主 Java 目录导入到测试目录 (IntelliJ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51117098/

相关文章:

Java 与 Groovy 继承和基于父类的线程上下文

java - Android:如何检测 Assets 文件夹中的目录?

android - 如何创建类似 Google Currents 的布局

android - 为什么 JDBC 不适用于 Android 开发

python - 使用 Python 将数据发布到 Firebase

java - Spring HtmlUnit 依赖

java - 在给定时区的 Android 上检索当前时间的错误

java - spring web starter中路径变量的自定义反序列化

javascript - TypeError : elements. get 不是 firebase 函数中的函数错误

javascript - Firebase 节点删除后 View 没有变化