在我尝试添加 AssertJ 后库到我的项目进行测试,我的项目中的某些配置发生了更改,并且我无法将 main 包中的任何类导入到我的 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"
}
最佳答案
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/