android studio Kotlin 单元测试 找不到自定义的类 Class not found

Android studio Kotlin 单元测试, 找不到自定义的类


问题描述:

在项目里面的一个模块,开始创建的是android-library,没有考虑使用kotiln,后面开始使用kotlin后,单元测试里面import自己的kotlin类,执行会报错“class not found”


原因分析:

查看此模块的gradle发现问题,没有开启kotlin插件,同时要增加kotlin的测试依赖库引用。


解决方案:

开启kotlin插件,同时要增加kotlin的测试依赖库引用

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'
	//....
}

猜你喜欢

转载自blog.csdn.net/lucky_tom/article/details/114663136