android - Class not found. Test class not found
问题描述
Here is it my sreen:
What settings should I set? How to avoid deprecated class?
I would like to use espresso, after that try to use UiAutomator, how to set needed necessary settings?
I lost almost whole day.
@RunWith(AndroidJUnit4::class)
@LargeTest
class MainActivityTest {
@Rule
@JvmField
var activityTest = ActivityTestRule(MainActivity::class.java)
fun c(){
assertEquals(1,1)
}
}
GRADLE
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.network"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
//okhttp library
implementation("com.squareup.okhttp3:okhttp:4.7.2")
// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
//gson
implementation 'com.google.code.gson:gson:2.8.6'
//recycler
implementation "androidx.recyclerview:recyclerview:1.1.0"
//picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//broadcast
implementation 'com.android.support:design:26.1.0'
//interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0'
}
解决方案
You've not set the test runner correctly.
This line:
"android.support.test.runner.AndroidJUnitRunner"
should be instead:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
as you are using the new androidx
libraries instead of the old support
ones.
Without this you'll get this No tests were found
errors. Don't forget to add the testInstrumentationRunner
keyword.
And add junit to androidTestImplementation also in de gradle file:
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
推荐阅读
- php - 如何创建数学方程是一个sql调用PHP
- javascript - 根据值 switch case 语句更改文本颜色的颜色
- python-3.x - 如何修复 dyld:库未加载... 原因:找不到图像 中止陷阱:6?
- python - Python Ctypes NULL 指针访问
- java - 制作动画和移动 JFrame
- php - 哪个更快,连接器或 PHP 原生函数
- angularjs - 在angularjs中的.html文件中刷新页面时调用方法
- ios - 在 didSelectRowAt indexPath 函数之外访问 IndexPath.row
- java - 在recyclerview中回收edittext
- swift - 如何实现一个符合相互关联协议之一的泛型类?