【问题标题】:Android Tests: java.lang.ClassNotFoundExceptionAndroid 测试:java.lang.ClassNotFoundException
【发布时间】:2020-12-07 15:58:47
【问题描述】:

我已经创建了这个 android 测试:

package fr.tisseo.android.repository.productlocalization.tests

import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4ClassRunner::class)
class TodeleteTest {
    @Test
    fun testTodelete(){
        Assert.assertTrue(true)
    }
}

我有这个 gradle 配置:

defaultConfig {
    ...
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

//Unit testing
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'

当我运行测试时,出现以下错误:

$ adb shell am instrument -w -r -e debug false -e class 'fr.tisseo.android.repository.productlocalization.tests.TodeleteTest' fr.tisseo.android.debug.test/androidx.test.runner.AndroidJUnitRunner 已连接到设备“google-pixel_3-89KX0AP57”上的进程 27190。

开始运行测试

java.lang.ClassNotFoundException: fr.tisseo.android.repository.productlocalization.tests.TodeleteTest

我在实施过程中遗漏了什么?

【问题讨论】:

    标签: android android-testing instrumented-test


    【解决方案1】:

    我在启动 AndroidTest 目标时遇到了类似问题。

    Caused by: java.lang.ClassNotFoundException: Didn't find class .... on path: DexPathList[[zip file
    

    我也使用了 Kotlin 源代码。在 Gradle 配置文件中添加 apply plugin: 'kotlin-android' 解决了我的问题。

    apply plugin: 'com.android.library'
    apply plugin: 'kotlin-android'
    
    ...
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 2013-10-25
      • 2011-08-08
      • 2015-01-29
      • 2017-01-26
      • 2020-02-08
      • 2017-04-16
      • 2017-01-02
      相关资源
      最近更新 更多