Android studio Kotlin unit test, cannot find custom class
Problem Description:
In a module in the project, the android-library was created at the beginning, and Kotiln was not considered. Later, after using Kotlin, import your own Kotlin class in the unit test, and the execution will report an error "class not found"
Cause Analysis:
Check the gradle of this module to find the problem, the kotlin plug-in is not enabled, and the test dependency library reference of kotlin needs to be added.
solution:
Open the kotlin plug-in, and add kotlin's test dependency library reference
plugins {
id 'com.android.library'
id 'kotlin-android' //增加这行
}
dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"//增加这行
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"//增加这行
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//....
}